Home Tutorial Java Core Java create triangle pattern

 
 

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

+
++
+++
++++
+++++
Advertisement

Related Tags for Java create triangle pattern:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 8, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com