-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestAndSmallest.java
More file actions
46 lines (36 loc) · 1.06 KB
/
LargestAndSmallest.java
File metadata and controls
46 lines (36 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
38
39
40
41
42
43
44
45
46
//LargestAndSmallest.java
import java.util.Scanner; // Needed for the scanner class
public class LargestAndSmallest
{
public static void main(String[] args)
{
double value; // Store user input
double smallest; // Smallest value
double largest = 0; // Larget value
// Create Scanner object
Scanner keyboard = new Scanner(System.in);
// Provide program information
System.out.println("Enter a series of numbers, when fishined enter '-99'");
// Get a number from the user
System.out.print("Enter a number: ");
value = keyboard.nextDouble();
// Assign first value as smallest
smallest = value;
// Begin a while loop to continue getting numbers from the user
while(value != -99)
{
System.out.print("Enter a number: ");
value = keyboard.nextDouble();
if(value != -99)
{
if (value > smallest)
largest = value;
else
smallest = value;
}
}
// Display largest and smallest value
System.out.println("Smallest Value: " + smallest);
System.out.println("Largest Value: " + largest);
}
}