-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleMaker.java
More file actions
41 lines (36 loc) · 901 Bytes
/
Copy pathTriangleMaker.java
File metadata and controls
41 lines (36 loc) · 901 Bytes
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
40
41
/*
* Jiarong Xu
*/
import java.util.Scanner;
public class TriangleMaker {
public static void main(String[] args) {
//greetings & get the size number
System.out.println("Welcome to Triangle Maker! Enter the size of the triangle. Please only enter number.");
Scanner keyboard = new Scanner(System.in);
int n = keyboard.nextInt();
keyboard.nextLine();
// start drawing when the number is correct
if (n > 0)
{
for(int i1 = 1; i1 <= n; i1++)
{
for(int j1=1; j1 <= i1; j1++)//draw * for each line
{
System.out.print("*");
}
System.out.println();//keep draw lines until reach the line n
}
// drawing the * in the reverse way
for(int i2 = n-1; i2>0; i2--)
{
for(int j2= i2; j2>0; j2--)
{
System.out.print("*");
}
System.out.println();
}
}
else
System.exit(0);//end the program when number is wrong
}
}