Advertisements

Program Sederhana Membuat Segitiga Sama Sisi pada Java

19 May

Cara membuat program segitiga sama sisi berikut ini menggunakan perulangan (loop) for, dengan sedikit modifikasi pada source code seperti dibawah ini

public class samasisi {

public static void main (String[] args) {
 int n = 10;
 for(int i=1; i<=n; i++) {
 for(int j=n; j>i; j--) {
 System.out.print(" ");
 }
 for(int k=1; k<=i; k++) {
 System.out.print("* ");
 }
 System.out.println();
 }
 System.out.println();
 System.out.print("baris = " + n);
 }
}

Output

segitiga samasisi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: