Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SmallLargest {
- public static void main(String[] args) {
- Double userNumber = null;
- double large = Double.MIN_VALUE;
- double small = Double.MAX_VALUE;
- //but then how can they type a higher number as the user
- System.out.print("Enter terminating number: ");
- double terminator = IO.readDouble();
- //For large you use min_value. So ANY number they type will be larger. And vice versa for small
- //Before you had -1000 as large's initializer. If they typed all numbers lower than it, -1000 would be the output which is wrong.
- while (true){
- System.out.print("Enter a number: ");
- userNumber = IO.readDouble();
- if(userNumber.equals(terminator)) break;
- if(userNumber >= large){
- large = userNumber;
- }
- if(userNumber <= small){
- small = userNumber;
- }
- }
- IO.outputDoubleAnswer(large);
- IO.outputDoubleAnswer(small);
- }
- }
Add Comment
Please, Sign In to add comment