Wednesday, 11 May 2016

JAVA Program for printing the triangle pattern


Input Format:

Enter N: 5

Output Format:

*
* *
* * *
* * * *
* * * * *
* * * *
* * * 
* * 


Program:

import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter N: ");
int height = ( Integer.parseInt( s.nextLine( ) ) );
StringBuffer str = new StringBuffer( );
for(int i = 0;i < height*2; i++){
      if( i > = height )
            str.deleteCharAt( 0 );
      else
            str.append("*");
      System.out.println(str);
}
}
}


0 comments:

Post a Comment