Home Tutorial Java Core Java create triangle pattern

 
 

Java create triangle pattern
Posted on: December 8, 2012 at 12:00 AM
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: +

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

Related Tags for Java create triangle pattern:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.