Monday, September 26, 2011 - 1 comments

Membuat persegi dengan isi karakter "X"

Output:

Code:

-----------------------------------------------

class Kotak_X {
    public static void main(String args[])
    {
        int N, J, I, kiri, kanan;
       

        N = 11;
        J = 0;
        I = 0;
        kiri = 0;
        kanan = N - 1;
       
        while(I < N)
        {
            while(J < N)
            {
                if(J == 0 || J == N - 1)
                    System.out.print("*");
                else
                {
                    if(I == 0 || I == N - 1)
                    {
                        System.out.print("*");
                    }
                    else
                    {
                        if(J == kiri || J == kanan)
                            System.out.print("*");
                        else
                            System.out.print(" ");
                    }
                }
               
                J++;
            }
            J = 0;
            System.out.println();
            I++;
            kiri++;
            kanan--;
        }
    }
}

-------------------------------------------------------

Download contoh.

Keep Lerning!!

1 comments:

Anonymous November 9, 2011 at 9:41 PM

trah mantabs...

Post a Comment