Java Examples – Print Parallelogram
Output a parallelogram.
Example
public class Parallelogram {
public static void main(String[] args) {
//Outer loop prints one * each time
for (int i = 1; i <=5; i++) {
//Fill spaces
for (int j = 1; j <= 5 - i; j++) {
System.out.print(" ");
}
//Inner loop prints one * each time
for (int k = 1; k <= 5; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output result:
*****
*****
*****
*****
*****
Other Extensions
Java Examples