Advertisement
LightProgrammer000

Valores Distintos [JOptionPane]

Jan 3rd, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package REVISÃO;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5.  
  6. public class Vetores_2
  7. {
  8.     static int TAM = 5;
  9.    
  10.     public static void main(String[] args)
  11.     {
  12.         // Variáveis
  13.         int i, j; // Controle de Fluxo
  14.         String ac = ""; // Acumlador
  15.         boolean alerta = true; // Flag
  16.         int [] n = new int[TAM]; // Vetor
  17.        
  18.         // Estrutura de Repetição: Entrada de Valores
  19.         for ( i = 0; i < TAM; i ++ )
  20.         {
  21.             n[i] = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite: " + (i + 1), "Numeros", JOptionPane.INFORMATION_MESSAGE));
  22.            
  23.             // Estrutura de Repetição:  
  24.             for ( j = 0; j < i; j++ )
  25.             {
  26.                 if( n[i] == n[j] )
  27.                 {
  28.                     n[i] = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite: " + (i + 1), "Numeros", JOptionPane.INFORMATION_MESSAGE));
  29.                     i--;
  30.                    
  31.                     alerta = false;
  32.                     break;
  33.                 }
  34.                
  35.                 else
  36.                 {
  37.                     alerta = true;
  38.                 }
  39.             }
  40.            
  41.             if (alerta == true)
  42.             {
  43.                 ac += n[i] + "\n";
  44.             }
  45.    
  46.         }
  47.                        
  48.         JOptionPane.showMessageDialog(null, ac);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement