Saturday, September 24, 2011 - 3 comments

Membuat tampilan bangun belah ketupat

Output :




Code :
------------------------------------------
public class Ketupat_2 {
    public static void main(String args[])
    {
        int N, kiri, kanan, I = 0, J = 0, X;
       
        N = 11;
       

        if(N % 2 == 1)
        {
            X = N / 2;
            kanan = X;
            kiri = X;
        }
        else
        {
            X = (N / 2) - 1;
            kanan = X;
            kiri = X;
        }
               
        while(I <= X)
        {
            while(J <= N)
            {
                if(J == kiri)
                {
                    while(J <= kanan)
                    {
                        System.out.print("*");
                        J++;
                    }
                }
                else
                {
                    System.out.print(" ");
                }
                J++;
            }
            System.out.println();
            J = 0;
            kiri--;
            kanan++;
            I++;
        }
       
        if(N % 2 == 1)
        {
            kiri += 2;
            kanan -= 2;
        }
        else
        {
            kiri += 1;
            kanan -= 1;
        }
       
        while(I > 1)
        {
            while(J <= N)
            {
                if(J == kiri)
                {
                    while(J <= kanan)
                    {
                        System.out.print("*");
                        J++;
                    }
                }
                else
                {
                    System.out.print(" ");
                }
                J++;
            }
            System.out.println();
            J = 0;
            kiri++;
            kanan--;
            I--;
        }
    }
   
}

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

Download contoh.

Penjelasan lebih? Silakan PM ane.

fauzan_adhima_alwan@yahoo.co.id

3 comments:

Dian Ayu Fauko Audini September 27, 2011 at 8:09 AM

Suwun banget Jan ya... :)

Arvin Abdillah October 5, 2011 at 6:03 AM

ga iso di copas zan .. o.O

Fawzan Adhima October 6, 2011 at 3:35 AM

Yo emang kagak bisa... biar agan ngetik... hehee

setidaknya, saya mengajak agan untuk belajar.. :)

Post a Comment