17 กรกฎาคม 2554

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

ข้อที่ 25.

****5*****
***444****
**33333***
*2222222**
111111111*

public class SuperLoop25 {
    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*2-1;j++){
                System.out.print(z-i+1);
            }
            for(int j=i;j<=z;j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }   
}
ข้อที่ 26.

11111*
2222**
333***
44****
5*****

public class SuperLoop26 {
    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;j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
ข้อที่ 27.

1 *
2  **
3   ***
4    ****
5     *****

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

ข้อที่ 28.

54321*12345
5432***2345
543*****345
54*******45
5*********5

public class SuperLoop28 {
    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(j);
            }
            for(int j=1;j<=i*2-1;j++){
                System.out.print("*");
            }
            for(int j=i;j<=z;j++){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}
ข้อที่ 29.

1*3***
2*4****
3*5*****
4*6******
5*7*******

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

1234567***3
123456****4
12345*****5
1234******6
123*******7

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

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

public class SuperLoop31 {
    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("*");
            }
            for(int j=i;j>=1;j--){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}
ข้อที่ 32.

11111*****
2222  ****
333    ***
44      **
5        *

public class SuperLoop32 {
    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("*");
            }
            System.out.println();
        }
    }
}

ข้อที่ 33.

    *
   ***
  *****
   ***
    *

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

    *
   *2*
  *232*
   *2*
    *

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

ข้อที่ 35.

   1*1*2
   2*3*4
   3*5*6
   4*7*8
   5*9*10

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

123*321
23***32
3*****3
23***32
123*321

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

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

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