-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListPrimes.java
More file actions
43 lines (35 loc) · 819 Bytes
/
ListPrimes.java
File metadata and controls
43 lines (35 loc) · 819 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
42
43
/**
* ListPrimes.java
* @author Herb Wolfe, Jr <hwolfe71@gmail.com>
*
* This program displays a list of prime numbers
*
*/
import static java.lang.System.*;
import java.util.*;
import java.io.*;
public class ListPrimes {
/**
* Interactive method to display prime numbers to console.
*/
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
Prime primes;
int count;
String tmp;
if (args.length == 0) {
out.print("Enter the number of primes to display: ");
tmp = in.next();
} else {
tmp = args[0];
}
try {
count = Integer.parseInt(tmp);
primes = new Prime(count);
primes.printAllPrimes();
} catch (NumberFormatException ex) {
out.println("Invalid entry, goodbye!");
}
return;
}
}