Skip to content

Instantly share code, notes, and snippets.

@juliosandino
Last active October 13, 2016 20:21
Show Gist options
  • Save juliosandino/c2f03f5c69b88e58e99f41bc20a0b945 to your computer and use it in GitHub Desktop.
Save juliosandino/c2f03f5c69b88e58e99f41bc20a0b945 to your computer and use it in GitHub Desktop.
public class Loops{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int rows = 0;
System.out.print("Chose a number: ");
while (in.hasNextInt()) {
rows = in.nextInt();
if (rows >= 2 && rows <= 20) {
break;
}
System.out.println("Please choose a number between 2 and 20");
}
for (int i = rows; i > 0; i--) {
for (int k = rows - i; k > 0; k--) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.print(" ");
for (int k = 0; k < rows + 1 - i; k++) {
System.out.print("*");
}
for (int l = 0; l < i; l++) {
System.out.print(" ");
}
for (int m = i; m > 1; m--) {
System.out.print(" ");
}
for (int n = rows + 1 - i; n > 0; n--) {
System.out.print("*");
}
System.out.print(" ");
for (int p = i; p > 0; p--) {
System.out.print("*");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment