-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram115.java
More file actions
26 lines (20 loc) · 902 Bytes
/
Program115.java
File metadata and controls
26 lines (20 loc) · 902 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
import java.util.Scanner;
class FindLargestAndSmallestNumbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number;
int largest = Integer.MIN_VALUE; // Initialize to the smallest possible integer
int smallest = Integer.MAX_VALUE; // Initialize to the largest possible integer
char choice;
do {
System.out.print("Enter a number: ");
number = scanner.nextInt();
largest = Math.max(largest, number);
smallest = Math.min(smallest, number);
System.out.print("Do you want to enter another number? (y/n): ");
choice = scanner.next().charAt(0);
} while (choice == 'y' || choice == 'Y');
System.out.println("Largest number entered: " + largest);
System.out.println("Smallest number entered: " + smallest);
}
}