17 กรกฎาคม 2554

โจทย์ พร้อมตัวอยางเฉลยโปรแกรม พิรามิด ทั้ง 36 ข้อ ^ ^

ข้อที่ 1.

11******11
 22****22
  33**33
   4444

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


ข้อที่ 2.

15*****
26******
37*******
48********

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

ข้อที่ 3.


123***
234****
345*****
456******

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


*1
**212
***32123
****4321234

public class SuperLoop04 {
    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>=1;j--){
                System.out.print(j);
            }
            for(int j=1;j<i;j++){
                System.out.print(j+1);
            }
            System.out.println();
        }
    }
}

ข้อที่ 5.


   11
  2**2
 3****3
4******4
 3****3
  2**2
   11

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

ข้อที่ 6.

123**
 234***
  345****
   456*****
    567******
     678*******
      789********

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

ข้อที่ 7.

      111
     12221
    1233321
   123444321
  12345554321
 1234566654321
123456777654321

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

1010101010101
 10101010101
  101010101
   1010101
    10101
     101
      1

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

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

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