Saturday, September 17, 2011 - 0 comments

Membuat tampilan bangun segitiga

Hasil Output :

Code :

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

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



Download Java file

0 comments:

Post a Comment

Artikel lain