Kamis, 05 Mei 2011

Bintang 5 & 6

-Input Bintang_5-

public class tugas_bintang5 {
public static void main (String [] args){
    int baris,m;
    for(int i=1;i<=7;i++){
        if(i<5){
        for (int j=1;j<=4;j++){
            if (j<=i)
                System.out.print("*");
            else
                System.out.print(" ");
        }}
        else{
            for (int j=1;j<=4;j++){
                m=i+j;
                if(m<=8)
                    System.out.print("*");
            else
                System.out.print(" ");

            }
        }
        System.out.println();
        }
    }

}



-Output-


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



-Input Bintang_6-

public class tugas_bintang6 {
public static void main (String [] args){
    int baris,m,x,y,n;
    for(int i=1;i<=7;i++){
        if(i<=4){
        for (int j=1;j<=7;j++){
            if (j<=4){
                m=i+j;
                if (5<=m)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        else{
                x=j-3;
                if(x<=i)
                     System.out.print("*");
            else
                System.out.print(" ");
        }
        }}
        else
            for (int j=1;j<=7;j++){
               if(j<=4){
               y=i-3;
               if(y<=j)
                    System.out.print("*");
            else
                System.out.print(" ");
               }
               else{
                   x=j-3;
                   y=i-3;
                   n=x+y;
                   if(n<=5)
                        System.out.print("*");
            else
                System.out.print(" ");
                 
            }
        }
        System.out.println();
        }
    }

}





-Output-

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

Tidak ada komentar:

Posting Komentar

chatme


ShoutMix chat widget