Advertisement
cesarnascimento

ex20 fernando repetição

Jun 3rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package exercicios;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ex20 {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Scanner sc = new Scanner(System.in);
  10.         int numero;
  11.         int maior = 0;
  12.         int menor = 0;
  13.         int total = 5;
  14.        
  15.         for(int i = 0;i<total;i++){
  16.             System.out.println("Digite o valor: ");
  17.             numero = sc.nextInt();
  18.            
  19.             if(i == 0){
  20.                 maior = numero;
  21.                 menor = numero;
  22.             }
  23.             if(numero > maior){
  24.                 maior = numero;
  25.             }
  26.             if(numero < menor){
  27.                 menor = numero;
  28.             }
  29.         }
  30.        
  31.         System.out.println("O maior número digitado é: "+maior);
  32.         System.out.println("O menor número digitado é: "+menor);
  33.        
  34.     }
  35. }
  36.     /* César N. */
  37.  
  38. //Receber X números e mostrar o maior e menor número digitado.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement