public class P22 { public static void main(String[] args) { for(int i=5; i>0; i--) { for(int j=5; j>0;j--) { if(i>=j) System.out.print(j+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1
public class p11 { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=1; j<=5;j++) { if(i<=j) System.out.print(i+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
public class p12 { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=1; j<=5;j++) { if(i<=j) System.out.print(j+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
public class p17 { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=1; j<=5;j++) { if(i<=j) System.out.print((char)(64+j)+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT A B C D E B C D E C D E D E E
public class P21 { public static void main(String[] args) { for(int i=5; i>0; i--) { for(int j=5; j>0;j--) { if(i>=j) System.out.print(i+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
public class p18 { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=1; j<=5;j++) { if(i<=j) System.out.print((char)(64+i)+" "); else System.out.print(" "); } System.out.println(); } } } OUTPUT A A A A A B B B B C C C D D E
No comments:
Post a Comment
If you have any doubts, please let me know