Tuesday, 1 March 2016

Types of pyramid programs pattern 19



Program

class Main{
public static void main(String args[]){
int i,j;
for(i=1;i<=1;i++){
for(j=5;j>=i;j--)
System.out.print("*");
System.out.print("\n");
for(j=1;j<=4-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
System.out.print("\n");
for(j=1;j<=3-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
System.out.print("\n");
for(j=1;j<=2-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
System.out.print("\n");
for(j=5;j>=i;j--)
System.out.print("*");
}
}
}

OUTPUT:-
C:\Users\saty\Desktop>javac 1.java
C:\Users\saty\Desktop>java Main
*****
   *
  *
 *
*****

No comments:

Post a Comment