Advertisement
veronikaaa86

08. Number sequence

Jun 3rd, 2023
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package forLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08NumberSequence {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int maxNum = Integer.MIN_VALUE;
  12.         int minNum = Integer.MAX_VALUE;
  13.         for (int i = 1; i <= n; i++) {
  14.             int currentNum = Integer.parseInt(scanner.nextLine());
  15.  
  16.             if (currentNum > maxNum) {
  17.                 maxNum = currentNum;
  18.             }
  19.  
  20.             if (currentNum < minNum) {
  21.                 minNum = currentNum;
  22.             }
  23.         }
  24.  
  25.         System.out.printf("Max number: %d%n", maxNum);
  26.         System.out.printf("Min number: %d%n", minNum);
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement