Advertisement
Spocoman

08. Number sequence

Aug 27th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberSequence {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int minNumber = Integer.MAX_VALUE;
  8.         int maxNumber = Integer.MIN_VALUE;
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             int number = Integer.parseInt(scanner.nextLine());
  12.  
  13.             if (number < minNumber) {
  14.                 minNumber = number;
  15.             }
  16.             if (number > maxNumber) {
  17.                 maxNumber = number;
  18.             }
  19.         }
  20.        
  21.         System.out.printf("Max number: %d\nMin number: %d", maxNumber, minNumber);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement