Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Caio Fernado de Sousa
- *O programa gera um vetor de 20 posiçoes de 0 a 20
- **separa os pares em um vetor e os impares em outro
- *os valores com zero na verdade sao nulos
- */
- package javaapplication13;
- import java.util.Random;
- /**
- *
- * @author caio
- */
- public class JavaApplication13 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int a[] = new int [20];//vetor Principal
- int b[] = new int [20];//vetor par
- int c[] = new int [20];//vetor impar
- int m = 0;//contador par
- int n = 0;//contador impar
- Random rand = new Random();
- for(int i = 0; i <20;i++)
- {
- a[i] = 1 + rand.nextInt(20);
- if(a[i] % 2 == 0)
- {
- b[m++] = a[i];//par
- }
- else
- {
- c[n++] = a[i]; //impar
- }
- }
- for( int w = 0; w< 20;w++)
- {
- System.out.println(" \t todo " + a[w] + "\t par " + b[w] + " \t impar " + c[w]);//
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement