Xadez

Max & Min numbers with loop

Apr 17th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Learning {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int maxNum = Integer.MIN_VALUE;
  10.  
  11.         for (int i = 0; i < n; i++) {
  12.             int num = Integer.parseInt(scanner.nextLine());
  13.             if (num > maxNum ){
  14.                 maxNum = num;
  15.             }
  16.         }
  17.         System.out.println(maxNum);
  18.  
  19.     }
  20. }
  21.  
  22. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23.  
  24.  
  25. import java.util.Scanner;
  26.  
  27. public class Learning {
  28.     public static void main(String[] args) {
  29.         Scanner scanner = new Scanner(System.in);
  30.  
  31.         int n = Integer.parseInt(scanner.nextLine());
  32.  
  33.         int minNum = Integer.MAX_VALUE;
  34.  
  35.         for (int i = 0; i < n; i++) {
  36.             int num = Integer.parseInt(scanner.nextLine());
  37.             if (num < minNum ){
  38.                 minNum = num;
  39.             }
  40.         }
  41.         System.out.println(minNum);
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment