Advertisement
Dido09

Java - Min and Max Number

Jul 7th, 2022
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None
  1. package SoftUniWeekFour;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class NumberSequence {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int minNumber = Integer.MAX_VALUE;
  10.         int maxNumber = Integer.MIN_VALUE;
  11.  
  12.         int n = Integer.parseInt(scanner.nextLine());
  13.         for (int i = 1; i <= n; i++) {
  14.             int num = Integer.parseInt(scanner.nextLine());
  15.             if (minNumber > num) {
  16.                 minNumber = num;
  17.             }
  18.             if (maxNumber < num) {
  19.                 maxNumber = num;
  20.             }
  21.         }
  22.         System.out.printf("Max number: %d\n", maxNumber);
  23.         System.out.printf("Min number: %d", minNumber);
  24.     }
  25. }
  26.  
Advertisement
RAW Paste Data Copied
Advertisement