-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetP.java
More file actions
36 lines (25 loc) · 908 Bytes
/
Copy pathsetP.java
File metadata and controls
36 lines (25 loc) · 908 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
package E3;
import java.util.Scanner;
public class setP {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
float input = 0, sum = 0, avg = 0, largest = -999999, smallest = 999999;
int count = 0;
System.out.println("Enter a set of floating-point values (type any letter to quit): ");
while (sc.hasNextFloat()) {
input = sc.nextFloat();
//Calculates sum and count to use for average calculation
sum += input;
count++;
//Calculates smallest and largest values
largest = Math.max(largest, input);
smallest = Math.min(smallest, input);
}
//Calculates average value and range between smallest and largest
avg = sum / count;
//Prints all calculations to user
System.out.println("Average value: " + avg);
System.out.println("Smallest value: " + smallest);
System.out.println("Largest value: " + largest);
}
}