*Tinggi piramida ditentukan oleh user
Membuat Piramida Menggunakan Perulangan Do-While:
Kode:
- import java.util.Scanner;
- public class latihan2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Masukkan tinggi piramida: ");
- int tinggi = input.nextInt();
- int i = 1;
- do{
- int j=i;
- do {
- if (j==tinggi){
- break;
- }
- System.out.print("-");
- j++;
- }while (j <= (tinggi-1));
- int k = 0;
- do {
- System.out.print("x");
- k++;
- }while (k <= (i*2) - 2);
- System.out.println(i);
- i++;
- }while (i <= tinggi);
- }
- }
Output:
Masukkan tinggi piramida: 10 ---------x1 --------xxx2 -------xxxxx3 ------xxxxxxx4 -----xxxxxxxxx5 ----xxxxxxxxxxx6 ---xxxxxxxxxxxxx7 --xxxxxxxxxxxxxxx8 -xxxxxxxxxxxxxxxxx9 xxxxxxxxxxxxxxxxxxx10
Baca juga Cara Membuat Piramida dengan perulangan while
👍👍👍😊
ReplyDelete:)
Delete:V
Deleteaassyaap :}
Deletedi python bang
ReplyDeletebisa ngga bg kalo di flowgorithm
ReplyDelete