This repository was archived by the owner on Sep 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
52 lines (48 loc) · 1.8 KB
/
Copy pathExample.java
File metadata and controls
52 lines (48 loc) · 1.8 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.InputMismatchException;
import java.util.Scanner;
public class Example {
public static void main(String args[]) {
int highest=-2147483648, lowest=2147483647, entered, total=0, count=0; //lowest & highest possible int values in java
double average;
Scanner input = new Scanner(System.in);
System.out.print("Enter an exam score (0 or below to quit): ");
try {
entered = input.nextInt();
while (entered>0) {
count++;
total+=entered;
if (count==1) {
highest=entered;
lowest=entered;
} else {
if (entered>highest) {
highest=entered;
}
if (entered<lowest) {
lowest=entered;
}
}
System.out.print("Enter an exam score (0 or below to quit): ");
entered = input.nextInt();
}
if (count>0) {
average = (double)total/count;
System.out.println("Highest Score: "+highest);
System.out.println("Lowest Score: "+lowest);
System.out.println("Average Score: "+average);
} else {
System.out.println("No Scores");
}
} catch (InputMismatchException e) {
System.out.println("Invalid entry");
if (count>0) {
average = total/(double)count;
System.out.println("Highest Score: "+highest);
System.out.println("Lowest Score: "+lowest);
System.out.println("Average Score: "+average);
} else {
System.out.println("No Scores");
}
}
}
}