-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path64.java
More file actions
106 lines (104 loc) · 2.9 KB
/
64.java
File metadata and controls
106 lines (104 loc) · 2.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*******************************************************************************
* 64) Escreva um programa que deverá ter as seguintes opções:
* 1 - Carregar Vetor
* 2 - Listar Vetor
* 3 - Exibir apenas os números pares do vetor
* 4 - Exibir apenas os números ímpares do vetor
* 5 - Exibir a quantidade de números pares existem nas posições ímpares do vetor
* 6 - Exibir a quantidade de números ímpares existem nas posições pares do vetor
* 7 - Sair
* Deverá ser implementado um método para realizar cada uma das opções de 1 a 6.
*******************************************************************************/
import java.util.Scanner;
public class Exercicio {
private static int[] Vetor = new int[10];
private static Scanner entrada = new Scanner(System.in);
public static void main(String[] args) {
boolean continuar = true;
while(continuar){
System.out.print("Digite uma opção: ");
int opcao = entrada.nextInt();
switch(opcao){
case 1:
CarregarVetor();
break;
case 2:
System.out.print(ListarVetor());
break;
case 3:
System.out.print(ListarParesVetor());
break;
case 4:
System.out.print(ListarImparesVetor());
break;
case 5:
System.out.print(QuantidadeParesNosImparesVetor());
break;
case 6:
System.out.print(QuantidadeImparesNosParesVetor());
break;
case 7:
continuar = false;
break;
default:
System.out.println("Número inválido.");
}
}
}
//1 - Carregar Vetor
public static void CarregarVetor(){
for(int x=0;x<10;x++){
System.out.print("Digite o "+(x+1)+"° número do vetor: ");
Vetor[x]= entrada.nextInt();
}
System.out.println("\nVetor carregado com sucesso!\n");
}
//2 - Listar Vetor
public static String ListarVetor(){
String ListaVetor = "Valores do vetor:\n";
for(int x=0;x<10;x++){
ListaVetor += "\t"+Vetor[x]+"\n";
}
return ListaVetor;
}
//3 - Exibir apenas os números pares do vetor
public static String ListarParesVetor(){
String ListaVetor = "Valores do vetor:\n";
for(int x=0;x<10;x++){
if(Vetor[x]%2==0){
ListaVetor += "\t"+Vetor[x]+"\n";
}
}
return ListaVetor;
}
//4 - Exibir apenas os números ímpares do vetor
public static String ListarImparesVetor(){
String ListaVetor = "Valores do vetor:\n";
for(int x=0;x<10;x++){
if(Vetor[x]%2==1){
ListaVetor += "\t"+Vetor[x]+"\n";
}
}
return ListaVetor;
}
//5 - Exibir a quantidade de números pares existem nas posições ímpares do vetor
public static int QuantidadeParesNosImparesVetor(){
int quantidade = 0;
for(int x=1;x<10;x=x+2){
if(Vetor[x]%2==0){
quantidade++;
}
}
return quantidade;
}
//6 - Exibir a quantidade de números ímpares existem nas posições pares do vetor
public static int QuantidadeImparesNosParesVetor(){
int quantidade = 0;
for(int x=0;x<10;x=x+2){
if(Vetor[x]%2==1){
quantidade++;
}
}
return quantidade;
}
}