desislava_topuzakova

06. Max Number

Jul 6th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. //команда => цяло число или "Stop"
  7. //повтаряме: проверка дали числото е мин
  8. //стоп: команда == "Stop"
  9. //продължаваме: команда != "Stop"
  10. int max = Integer.MIN_VALUE;
  11. String command = scanner.nextLine();
  12. while (!command.equals("Stop")) {
  13. //число под формата на текст -> command = "23"
  14. int number = Integer.parseInt(command);
  15. //проверка дали е максимум
  16. if(number > max) {
  17. max = number;
  18. }
  19.  
  20. command = scanner.nextLine();
  21. }
  22.  
  23. System.out.println(max);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment