Ayuda por favor, código java
Publicado por Marcos (5 intervenciones) el 10/10/2019 23:56:28
Hola necesito ayuda con este codigo, me da error en el case 3 y dice orphaned case pero no se por que.
Gracias
Gracias
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
int a[]=new int [6];
String nbr[]=new String [5];
Scanner teclado=new Scanner(System.in);
int menu = 5;
String Menu;
boolean salir = false;
int opcion;
while (!salir){
System.out.println("========<MENU>========");
System.out.println("1-Ingreso de Números");
System.out.println("2-Ordenar Números de forma decreciente");
System.out.println("3-Cantidad de pares e impares");
System.out.println("4-Ingreso de Nombres");
System.out.println("5-Ordenar alfabeticamente");
System.out.println("6-Salir");
try {
System.out.println("Escribe una de las opciones");
opcion = teclado.nextInt();
switch (opcion)
{
case 1:
System.out.println("Has seleccionado la opción 1");
for (int i=0;i<a.length;i++){
System.out.println("Ingrese el número " + (i+1) );
a[i]=teclado.nextInt();
}
break;
case 2:
int aux;
for(int i = 0; i < a.length; i++){
for(int j=i+1; j < a.length; j++){
if(a[i] < a[j]){
aux = a[i];
a[i] = a[j];
a[j] = aux;}}
System.out.println("Los números ordenados en forma decreciente son: ");
for (int y=0;y<a.length;y++){
System.out.println(a[y]);
}
break;
case 3:
int par=0;
int impar=0;
for (int o=0;o<a.length;o++){
if(a[o]%2==0){
par++;
}
if(a[o]%2!=0){
impar++;
}
}
System.out.println("La cantidad de numeros pares en el array son: " + par );
System.out.println("La cantidad de numeros impares en el array son: " + impar );
break;
case 4:
System.out.println("Ingrese 5 nombres: ");
for(int i=0;i<nbr.length;i++){
System.out.print("Ingrese el nombre " + (i+1) + ": ");
nbr[i]=teclado.nextLine();
}
break;
case 5:
String aux1;
for(int g=0;g<nbr.length;g++){
for(int j=0;j<nbr.length -1;j++){
if (nbr[j].compareTo(nbr[j+1]) > 0){
aux1=nbr[j];
nbr[j]=nbr[j+1];
nbr[j+1]=aux1;
}
}
}
System.out.println("Nombres Ordenados:");
for(int o=0;o<a.length;o++){
System.out.println("El nombre " + (o+1) + " es: " +nbr[o]);
}
break;
case 6:
salir=true;
break;
default: System.out.println("Número no válido");
break;
}
}
} catch (InputMismatchException e) {
System.out.println("Debes insertar un número");
teclado.next();
}
}
}
}
Valora esta pregunta


0