Pascal triangle 2

This program will display the pascal triangle or print star pattern as shown in output. 
System.out.print("....."): are used for display message on screen or console but cursor not move in new line. 
System.out.println("....."): are used for display message on screen or console cursor move in new line.


PROGRAM
class PascalTriangle2 {

 public static void main(String[] args) {
  
  for(int i=0; i<5; i++) {
   
   for(int j=0; j<=i; j++) {
    
    // This loop will show star '*'
    System.out.print("* ");
   }
   System.out.println("");
  }

 }

}
OUTPUT
C:\>javac PascalTriangle2.java
C:\>java PascalTriangle2

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

Comments

Popular posts from this blog

Develop an Android application to display “Hello World!” on screen

Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Build a Simple Android App to Display Student Details