-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPascalsTriangleDriver.java
53 lines (45 loc) · 1.44 KB
/
PascalsTriangleDriver.java
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
42
43
44
45
46
47
48
49
50
51
52
53
/*
* **********************************************
* San Francisco State University
* CSC 220 - Data Structures
* File Name: PascalsTriangleDriver.java
* Author: Java Foundation
* Author: Duc Ta
* Author: Bryan Khor
* **********************************************
*/
// Please DO NOT CHANGE this file.
package assignment03PartD;
import java.util.InputMismatchException;
import java.util.Scanner;
public class PascalsTriangleDriver {
private static String goodbye = "Adiós!";
public static void main(String[] args) {
int rowNum = getRowNum();
while (rowNum >= 0) {
PascalsTriangleGenerator p = new PascalsTriangleGenerator();
int[] row = p.computeRow(rowNum + 1);
for (int num : row) {
System.out.print(num + " ");
}
System.out.println();
rowNum = getRowNum();
}
System.out.println(goodbye);
}
private static int getRowNum() throws InputMismatchException {
Scanner input = new Scanner(System.in);
System.out.print("Enter a row of Pascal's Triangle: ");
int rowNum = -1;
try {
rowNum = input.nextInt();
input.nextLine();
} catch (InputMismatchException e) {
System.err.println(goodbye);
System.exit(1);
} finally {
// System.out.println("InputMismatchException handled.");
}
return rowNum;
}
}