-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx_04_Vetor.java
More file actions
36 lines (31 loc) · 1.08 KB
/
Ex_04_Vetor.java
File metadata and controls
36 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*04-Elaborar um programa que leia 10 elementos do tipo inteiro em um vetor A. Crie um vetor ParImpar de 2 posições
e armazene no índice 0 quantos elementos de A são par e no índice 1 quantos elementos de A são ímpar. Apresentar
vetor ParImpar. Obs.: não utilize o comando condicional se.
*/
import java.util.Scanner;
class Ex_04_Vetor
{
public static void main(String[] args)
{
Scanner leia = new Scanner(System.in);
int tamvet = 10, aux = 0;
int[] vet1 = new int[tamvet];
int[] ParImpar = new int[]{0,0};
System.out.println("\nLeitura do vetor A:\n");
for (int i = 0; i < tamvet; i++)
{
System.out.print("vet1[" + i + "]= ");
vet1[i] = leia.nextInt();
}
for(int a = 0; a < tamvet; a++)
{
aux = vet1[a]%2;
ParImpar[aux] += 1;
aux = 0;
}
System.out.print("\nConteúdo do vetor ParImpar: ");
for (int i = 0; i < 2; i++)
System.out.print(ParImpar[i] + "\t");
System.out.println();
}
}