forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMax.java
More file actions
29 lines (24 loc) · 644 Bytes
/
Max.java
File metadata and controls
29 lines (24 loc) · 644 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
import java.util.Arrays;
/**
* Demonstrates command-line arguments.
*/
public class Max {
/**
* Converts args to integers and prints the max.
*/
public static void main(String[] args) {
System.out.println(Arrays.toString(args));
if (args.length == 0) {
System.err.println("Usage: java Max <numbers>");
return;
}
int max = Integer.MIN_VALUE;
for (String arg : args) {
int value = Integer.parseInt(arg);
if (value > max) {
max = value;
}
}
System.out.println("The max is " + max);
}
}