Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- int maxNum = Integer.MIN_VALUE; // Set the minimum value for Integer
- int minNum = Integer.MAX_VALUE; // Set the maximum value for Integer
- while (!"END".equals(input)) { // Util the input is "END" keep rolling...
- int currentNumber = Integer.parseInt(input); // parsing the input to a number.
- if (maxNum < currentNumber) {
- maxNum = currentNumber;
- /* If the maxNum value is smaller than the currentNumber,
- set currentNumber value to maxNum
- */
- }
- if (minNum > currentNumber) {
- minNum = currentNumber;
- /* If the minNum value is bigger than the currentNumber,
- set currentNumber value to minNum
- */
- }
- input = scanner.nextLine();
- // read the next line, avoiding infinity loop.
- }
- System.out.printf("Max number: %d%n", maxNum);
- System.out.printf("Min number: %d", minNum);
- // Printing both numbers
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement