-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception02.java
More file actions
37 lines (35 loc) · 1.06 KB
/
Copy pathexception02.java
File metadata and controls
37 lines (35 loc) · 1.06 KB
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
import java.util.InputMismatchException;
import java.util.Scanner;
public class exception02 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i = 0;
int max = -999;
while (i != -1) {
try {
System.out.println("Enter a positive integer:");
i = input.nextInt();
max = Math.max(max, i);
} catch (InputMismatchException e) {
System.out.println("ERROR: Invalid input!");
break;
}
}
if (max < 0) {
System.out.println("No valid input entered!");
} else {
System.out.printf("The maximum integer is %d.", max);
}
}
private static int getSumSquares(String[] strings) {
int sum = 0;
for (int i = 0; i < strings.length; i++) {
try {
sum += Math.pow(Integer.parseInt(strings[i]), 2) ;
} catch (Exception e) {
continue;
}
}
return sum;
}
}