galinyotsev123

ProgBasics05while-Loop-P04numberSequence

Jan 6th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04numberSequence {
  4.  
  5. public static void main(String[]args){
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String command;
  9.  
  10. int min = Integer.MAX_VALUE;
  11. int max = Integer.MIN_VALUE;
  12.  
  13. while (true){
  14. command = scanner.nextLine();
  15.  
  16. if (command.equalsIgnoreCase("end")){
  17. break;
  18. }
  19.  
  20. int currentNum = Integer.parseInt(command);
  21.  
  22. if(currentNum < min){
  23. min = currentNum;
  24. }
  25.  
  26. if(currentNum > max){
  27. max = currentNum;
  28. }
  29. }
  30.  
  31. System.out.printf("Max number: %d%n", max);
  32. System.out.printf("Min number: %d%n", min);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment