desislava_topuzakova

08. Number sequence

May 9th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 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.         int n = Integer.parseInt(scanner.nextLine());
  7.         //за всяко едно число от 1 до n
  8.         //повтаряме: прочитаме си стойността, проверим дали е макс или мин
  9.         //преминаваме към следващото
  10.         int min = Integer.MAX_VALUE;
  11.         int max = Integer.MIN_VALUE;
  12.  
  13.         for (int number = 1; number <= n; number++) {
  14.             int value = Integer.parseInt(scanner.nextLine());
  15.             //стойността е макс
  16.             if (value > max) {
  17.                 max = value;
  18.             }
  19.  
  20.             //проверка за стойността дали е мин
  21.             if (value < min) {
  22.                 min = value;
  23.             }
  24.         }
  25.  
  26.         System.out.println("Max number: " + max);
  27.         System.out.println("Min number: " + min);
  28.  
  29.     }
  30. }
Add Comment
Please, Sign In to add comment