Advertisement
caiofersousa

Untitled

Nov 26th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. /*
  2. *Caio Fernado de Sousa
  3. *O programa gera um vetor de 20 posiçoes de 0 a 20
  4. **separa os pares em um vetor e os impares em outro
  5. *os valores com zero na verdade sao nulos
  6.  */
  7.  
  8. package javaapplication13;
  9.  
  10. import java.util.Random;
  11.  
  12. /**
  13.  *
  14.  * @author caio
  15.  */
  16. public class JavaApplication13 {
  17.  
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) {
  23.         // TODO code application logic here
  24.         int a[] = new int [20];//vetor Principal
  25.         int b[] = new int [20];//vetor par
  26.         int c[] = new int [20];//vetor impar
  27.         int m = 0;//contador par
  28.         int n = 0;//contador impar
  29.        
  30.         Random rand = new Random();
  31.         for(int i = 0; i <20;i++)
  32.         {
  33.             a[i] = 1 + rand.nextInt(20);
  34.             if(a[i] % 2 == 0)
  35.                 {
  36.                         b[m++] = a[i];//par
  37.                 }
  38.             else
  39.             {  
  40.                         c[n++] = a[i]; //impar                    
  41.            
  42.                 }
  43.         }
  44.         for( int w = 0; w< 20;w++)
  45.         {
  46.             System.out.println(" \t todo  " + a[w] + "\t par  " + b[w] + " \t impar  " + c[w]);//
  47.         }
  48.     }
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement