0% found this document useful (0 votes)
8 views5 pages

Tugas Looping

This document discusses different ways to create pyramid shapes using loops in Java. It provides 5 examples of code to generate pyramids using while and for loops, with varying numbers of spaces and asterisks in each row.

Uploaded by

akoiko02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Tugas Looping

This document discusses different ways to create pyramid shapes using loops in Java. It provides 5 examples of code to generate pyramids using while and for loops, with varying numbers of spaces and asterisks in each row.

Uploaded by

akoiko02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

tugas looping

USING NET Beans

Nama penyusun: FAUZA NURMAINI


Guru pwmimbing: ARIEFAN DANU PUTRA S.kom

PEMOGRAMAN WEB

1.PIRAMIDA

import java.util.Scanner;

public class loop{


public static void main(String[] args) {
int rows = 5;
int i = 1;

while (i <= rows) {


int j = 1;
while (j <= i) {
System.out.print("*");
j++;
}
public class loop3 {
public static void main(String[] args) {

int rows = 5;
int i = 1;

while (i <= rows) {


int j = rows;

while (j > i) {
System.out.print(" ");
j--;
}

int k = 1;
while (k <= i) {
System.out.print("* ");
k++;
}

System.out.println(); i++;
}

3. PIRAMIDA

public class loop4 {


public static void main(String[] args) {

int rows = 5;
int i = rows;

while (i >= 1) {
int j = 1;

while (j <= i) {
System.out.print("* ");
j++;
}

System.out.println();
i--;
}
}
}

4. PIRAMIDA
public class loop5 {
public static void main(String[] args) {

int rows = 5;
int i = 1;

while (i <= rows) {


int space = 1;
while (space < i) {
System.out.print(" ");
space++;
}

int j = 1;
while (j <= (rows - i + 1)) {
System.out.print("* ");
j++;
}

System.out.println();
i++;
}
}

5.PIRAMIDA
public class loop2 {
public static void main(String[] args) {
int rows = 5;

for (int i = 1; i <= rows; i++) {

for (int j = 1; j <= rows - i; j++) {


System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}

System.out.println(); // Move to the next line


}
}
}

You might also like