Pascal triangle 3

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 PascalTriangle3 {

 public static void main(String[] args) {

  for(int i=5; i>0; i--) {
   
   for(int j=0; j<i; j++) {
    
    // This loop will show star '*'
    System.out.print("* ");
   }
   System.out.println("");
  }
 }

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

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

Comments

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to draw Smiley in Applet