-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindLargestSmallestAverage.java
More file actions
44 lines (30 loc) · 1.14 KB
/
Copy pathFindLargestSmallestAverage.java
File metadata and controls
44 lines (30 loc) · 1.14 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
import java.util.Scanner;
public class FindLargestSmallestAverage {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int largest = Integer.MIN_VALUE;
int smallest = Integer.MAX_VALUE;
int sum = 0;
int count = 0;
char choice;
do {
System.out.print("Enter a number: ");
int number = scanner.nextInt();
largest = Math.max(largest, number);
smallest = Math.min(smallest, number);
sum += number;
count++;
System.out.print("Do you want to enter another number? (Y/N): ");
choice = scanner.next().charAt(0);
} while (choice == 'Y' || choice == 'y');
if (count > 0) {
double average = (double) sum / count;
System.out.println("Largest number: " + largest);
System.out.println("Smallest number: " + smallest);
System.out.println("Average: " + average);
} else {
System.out.println("No numbers entered.");
}
scanner.close();
}
}