-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactors.java
More file actions
46 lines (38 loc) · 936 Bytes
/
factors.java
File metadata and controls
46 lines (38 loc) · 936 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
44
45
46
/**
* factors.java
* @author Herb Wolfe, Jr <hwolfe71@gmail.com>
*
* Created: 01/03/2014
*
* This program displays a list of the prime factors of a number.
* The number can either be passed as a command line parameter, or
* interactively.
*
*/
import static java.lang.System.*;
import java.util.*;
import java.io.*;
public class factors {
/**
* Interactive method to display whether or not a number is prime.
*/
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
Prime primes = new Prime();
long num;
String tmp;
if (args.length == 0) {
out.print("Enter the number to list its factors: ");
tmp = in.next();
} else {
tmp = args[0];
}
try {
num = Long.parseLong(tmp);
primes.printFactors(num);
} catch (NumberFormatException ex) {
out.println("Invalid entry, goodbye!");
}
return;
}
}