Thursday, 17 March 2011

Contoh Program Java (Membuat Piramida)


package tr2;

/**
 *
 * @author zefy
 */

      // Berkas: Piramida.java
      // Berkas: TesInterface2.java

public class Main {
   public static void main(String[] args) {
      System.out.println("Masukkan tinggi piramida (2..20):"); //untuk tinggi piramida
      String st = baca.bacaString();      int row, colom;
      int tinggi = Integer.valueOf(st).intValue();
      for (row = 1; row <= tinggi ; row++) {
            for (colom = 1; colom <= tinggi - row; colom++)
            System.out.print(" ");  // Karakter spasi
         for (colom = 1; colom < 2 * row; colom++)
             System.out.print("*");
         System.out.println("");
      }
   }
}

No comments:

Post a Comment

COPYRIGHT © 2017 · ZARLINDA | THEME BY RUMAH ES