ini adalah pembahasan salah satu soal UTS Pemrograman Java.
# Tentang Perulangan.
package test;
import javax.swing.JOptionPane;
public class UTS1 {
public static void main(String[] args) {
int a = Integer.valueOf(JOptionPane.showInputDialog("Masukkan Angka"));
for (int i = 1; i <= a; i++) {
for (int j = 0; j < a - i; j++) {
System.out.print(" ");
}
System.out.print("+");
for (int k = 0; k < i; k++) {
System.out.print("--+");
}
System.out.println();
for (int l = 0; l < a - i; l++) {
System.out.print(" ");
}
System.out.print("|");
for (int m = 0; m < i; m++) {
System.out.print(" |");
}
System.out.println();
}
System.out.print("+");
for (int i = 0; i < a; i++) {
System.out.print("--+");
}
}
}
outputnya =
+--+
| |
+--+--+
| | |
+--+--+--+
| | | |
+--+--+--+
0 comments:
Posting Komentar