Program: 16
Output:
Program: 17
Output:
Program: 18
Output:
Program: 19
Output:
Program: 20
Output:
public class HelloWorld{ public static void main(String []args){ for(int i=9;i>=1;i-=2){ for(int k=i;k<9;k+=2) System.out.print(" "); for(int j=1;j<=i;j++){ System.out.print(i); } System.out.println(""); } } }
Output:
9 9 9 9 9 9 9 9 9 7 7 7 7 7 7 7 5 5 5 5 5 3 3 3 1
Program: 17
public class HelloWorld{ public static void main(String []args){ for(int i=9;i>=1;i-=2){ for(int k=i;k<9;k+=2) System.out.print(" "); for(int j=1;j<=i;j++){ System.out.print(j); } System.out.println(""); } } }
Output:
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 1 2 3 4 5 1 2 3 1
Program: 18
public class HelloWorld{ public static void main(String []args){ for(int i=1;i<=11;i++){ for(int j=1;j<=10;j++){ if((j<(2+((11/2)-(i)))) || (j>=(11-((11/2)-(i-1))))) System.out.print(i); else System.out.print(" "); } System.out.println(""); } } }
Output:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5
Program: 19
public class HelloWorld{ public static void main(String []args){ for(int i=1;i<=11;i++){ for(int j=1;j<=10;j++){ if((j<(2+((11/2)-(i)))) || (j>=(11-((11/2)-(i-1))))) System.out.print(j); else System.out.print(" "); } System.out.println(""); } } }
Output:
1 2 3 4 5 6 7 8 9 10 1 2 3 4 7 8 9 10 1 2 3 8 9 10 1 2 9 10 1 10
Program: 20
public class HelloWorld{ public static void main(String []args){ for(int i=11;i>=1;i--){ for(int j=1;j<10;j++){ if((j<(2+((11/2)-(i)))) || (j>=(11-((11/2)-(i-2))))) System.out.print(i); else System.out.print(" "); } System.out.println(""); } } }
Output:
5 5 4 4 4 4 3 3 3 3 3 3 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1
No comments:
Post a Comment