desislava_topuzakova

06. Max Number

Oct 9th, 2021
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumNumbers_07 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.        //повтарям: число под формата на текст -> число
  7.         //спираме: вход == "Stop"
  8.         //продължаваме: вход != "Stop"
  9.         /*int max = Integer.MIN_VALUE;
  10.         String input = scanner.nextLine(); //"Stop" или число под формата на текст
  11.         while (!input.equals("Stop")) {
  12.             //число под формата на текст -> "100"
  13.             //текст -> число (parse)
  14.             int number = Integer.parseInt(input);
  15.             //проверка дали е макс
  16.             if (number > max) {
  17.                 max = number;
  18.             }
  19.  
  20.             input = scanner.nextLine();
  21.         }
  22.         System.out.println(max);*/
  23.  
  24.         int max = Integer.MIN_VALUE;
  25.         for (String input = scanner.nextLine(); !input.equals("Stop") ; input = scanner.nextLine()) {
  26.             int number = Integer.parseInt(input);
  27.             //проверка дали е макс
  28.             if (number > max) {
  29.                 max = number;
  30.             }
  31.         }
  32.  
  33.         System.out.println(max);
  34.  
  35.  
  36.  
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment