Source code java
import javax.swing.*;
public class Segi6 {
public static void main(String[] args) {
int tinggi = Integer.parseInt (JOptionPane.showInputDialog ("Masukkan Tinggi:"));
String s = "";
for (int i=3; i<tinggi; i++){
for (int j=0; j<tinggi-i; j++)
s += " ";
for (int j=0; j<2*i-1; j++)
s += "* ";
s += "\n";
}
for (int i=tinggi; i>2; i--){
for (int j=0; j<tinggi-i; j++)
s += " ";
for (int j=0; j<2*i-1; j++)
s += "* ";
s += "\n";
}
System.out.println ("Baris = " + tinggi + "\n\n" + s);
System.exit(0);
}
}
Tidak ada komentar:
Posting Komentar