Program
class Main{
public static void main(String args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
for(i=4;i>=1;i--){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
}
}
public static void main(String args[]){
int i,j;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
for(i=4;i>=1;i--){
for(j=1;j<=i;j++)
System.out.print(" "+j);
for(j=i-1;j>=1;j--)
System.out.print(" "+j);
System.out.println(" ");
}
}
}
OUTPUT:-
C:\Users\Saty\Desktop\java>javac
1.java
C:\Users\Saty\Desktop\java>java
Main
11 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
No comments:
Post a Comment