17 กรกฎาคม 2554

โจทย์ พร้อมตัวอยางเฉลยโปรแกรม พิรามิด ทั้ง 36 ข้อ ^ ^ (ชุดที่ 2)

ข้อที่ 9.

111111111
 2222222
  33333
   444
    5

public class SuperLoop09 {
    public static void main(String den[]){
        int z=6;
        for(int i=1;i<=z;i++){
            for(int j=1;j<i;j++){
                System.out.print(" ");
            }
            for(int j=i;j<=(z*2)-i;j++){
                System.out.print(i);
            }
            System.out.println();
        }
    }
}
ข้อที่ 10.

/*
    151
   12421
  1233321
 123424321
12345154321
 */
public class SuperLoop10 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=i;j<z;j++){
                System.out.print(" ");
            }
            for(int j=1;j<=i;j++){
                System.out.print(j);
            }
            System.out.print(z-i+1);
            for(int j=i;j>=1;j--){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}
ข้อที่ 11.

    11
   2 2
  3  3
 4   4
5    5

public class SuperLoop11 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=z;j>i;j--){
                System.out.print(" ");
            }
            System.out.print(i);
            for(int j=1;j<i;j++){
                System.out.print(" ");
            }
            System.out.println(i);
        }
    }
}
ข้อที่ 12.

123456789
 2345678
  34567
   456
    5

public class SuperLoop12 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=1;j<i;j++){
                System.out.print(" ");
            }
            for(int j=i;j<=(z*2-i);j++){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}
ข้อที่ 13.

987654321
  7654321
    54321
      321
        1

public class SuperLoop13 {
    public static void main(String den[]){
        int z=4;
        for(int i=1;i<=z;i++){
            for(int j=1;j<i*2-1;j++){
                System.out.print(" ");
            }
            for(int j=z*2-(i*2-1);j>=1;j--){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}
ข้อที่ 14.

12        21
 23      32
  34    43
   45  54
    5665

public class SuperLoop14 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=i;j>1;j--){
                System.out.print(" ");
            }
            System.out.print(i+""+(i+1));
            for(int j=z;j>i;j--){
                System.out.print("  ");
            }
            System.out.println((i+1)+""+i);
        }
    }
}
ข้อที่ 15.


11111 11111
2222   2222
333     333
44       44
5         5

public class SuperLoop15 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=i;j<=z;j++){
                System.out.print(i);
            }
            for(int j=1;j<=(i*2-1);j++){
                System.out.print(" ");
            }
            for(int j=i;j<=z;j++){
                System.out.print(i);
            }
            System.out.println();
        }
    }
}
ข้อที่ 16.


1        *
21      **
321    ***
4321  ****
54321*****

public class SuperLoop16 {
    public static void main(String den[]){
        int z=5;
        for(int i=1;i<=z;i++){
            for(int j=i;j>=1;j--){
                System.out.print(j);
            }
            for(int j =i;j<z*2-i;j++){
                System.out.print(" ");
            }
            for(int j=1;j<=i;j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น