forked from sweskills/prog-method-assignment-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindRange.java
30 lines (26 loc) · 1.03 KB
/
FindRange.java
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
import acm.program.*;
class FindRange extends ConsoleProgram{
public static int SENTINEL = 0;
public void run(){
System.out.println("The program finds the largest and smallest values");
int firstNumber = readInt("Enter first number");
int smallestNmber = firstNumber;
int largestNumber = firstNumber;
if (firstNumber == SENTINEL)
System.out.print("You did not enter a valid value");
else
System.out.println("you can now enter others");
int otherNumber = readInt("Enter other integers");
while(true){
if(otherNumber <= SENTINEL){
System.out.println(firstNumber+ "is the largest as well as th smallst");
}
else{
largestNumber = otherNumber;
if(otherNumber > largestNumber)
largestNumber = otherNumber;
}
System.out.print("Largest number: "+largestNumber);
}
}
}