Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         Scanner sc = new Scanner(System.in);
  3.  
  4.         System.out.print("Introduzca el número de valores que va a introducir: ");
  5.         int val = sc.nextInt();
  6.         int cont = 0;
  7.         int num, max = 0, min = 0;
  8.  
  9.         while (cont < val) {
  10.  
  11.             System.out.print("Ingrese un numero: ");
  12.             num = sc.nextInt();
  13.  
  14.             if (min != 0 && max != 0) {
  15.  
  16.                 if (num > max) {
  17.                     max = num;
  18.                 }
  19.                 if (num < min) {
  20.                     min = num;
  21.                 }
  22.             } else {
  23.                 min = num;
  24.                 max = num;
  25.             }
  26.             cont ++;
  27.         }
  28.         System.out.println("El número mayor es: " + max);
  29.         System.out.println("El número menor es: " + min);
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement