-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarioPyramid
39 lines (34 loc) · 952 Bytes
/
MarioPyramid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.signatureschool;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int height = getNumber();
buildPyramid(height);
}
public static int getNumber() {
Scanner sc = new Scanner(System.in);
int number = 0;
System.out.println("Enter a number:");
if (sc.hasNextInt()) {
number = sc.nextInt();
} else {
return getNumber();
}
if (number > 0 && number < 9) {
return number;
} else {
return getNumber();
}
}
public static void buildPyramid(int height) {
for (int i = 0; i < height; i++) {
for (int k = height - 1; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print("#");
}
System.out.println("#");
}
}
}