if input is::4
4 4 4 4
3 3 3
2 2
1
2 2
3 3 3
4 4 4 4
program::
public class Comment {
public static void main( String arg[]){
int input = 4; //change it accordingly
for(int i=1 ; i<=input ; i++){
for(int j=1 ; j<=input-i+1 ; j++){
System.out.print(input-i+1+" ");
}
System.out.println();
}
for(int k=input-1; k>0 ; k--){
for(int l=2 ; l<=input-k+2 ; l++){
System.out.print(input-k+1+" ");
}
System.out.println();
}
}
}
public static void main( String arg[]){
int input = 4; //change it accordingly
for(int i=1 ; i<=input ; i++){
for(int j=1 ; j<=input-i+1 ; j++){
System.out.print(input-i+1+" ");
}
System.out.println();
}
for(int k=input-1; k>0 ; k--){
for(int l=2 ; l<=input-k+2 ; l++){
System.out.print(input-k+1+" ");
}
System.out.println();
}
}
}
3 comments:
Above Complete code is copied from Print Star Pattern in Java please remove this code
Post a Comment