Java create triangle pattern


 

Java create triangle pattern

In this tutorial, you will learn how to create a triangle shape.

In this tutorial, you will learn how to create a triangle shape.

Java create triangle pattern

In this tutorial, you will learn how to create a triangle shape. For this, user is allowed to enter number of lines to display the triangle of that length and a symbol to show the triangle in a particular symbol.

Example:

import java.util.*;

 public class Symbols {
	 public static void main(String[] args) {
	  Scanner read = new Scanner (System.in);
	  int nline, count, countl, nspace= 0, i;
	  char symbol;
	  System.out.print(" how many lines you want to print? ");
	  nline= read.nextInt();
	  System.out.print("what is the symbol you want to use: ");
	  symbol= read.next().charAt(0);
	  for (countl=1; countl<=nline; countl++){
		System.out.println();
		for(count=1; count<=countl; count++)
			System.out.print(symbol);
		 }
	}
}

Output:

 how many lines you want to print? 5
what is the symbol you want to use: +

+
++
+++
++++
+++++

Ads