corregir leer caracteres

This commit is contained in:
PC de clase committed 2026-10-15 13:23:41 +02:00
1 parent be3915fa3c
commit d92b72dcf0
2 files changed
+35 -4

No files matched your search

+17 -4
View File
@@ -4,7 +4,7 @@
import java.util.Scanner;
void main() {
long result = 0;
long a = 0, e = 0, i = 0, o = 0, u = 0;
Scanner sc = new Scanner(System.in);
@@ -15,13 +15,26 @@ void main() {
do {
char c = sc.next().charAt(0);
switch (c) {
case 'a', 'e', 'i', 'o', 'u':
result++;
case 'a':
a++;
break;
case 'e':
e++;
break;
case 'i':
i++;
break;
case 'o':
o++;
break;
case 'u':
u++;
break;
default:
}
} while (--n > 0);
sc.close();
System.out.printf("Hay %d vocales\n", result);
System.out.printf("a: %d\ne: %d\ni: %d\no: %d\nu: %d\n", a, e, i, o, u);
}
+18
View File
@@ -0,0 +1,18 @@
void main() {
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.US);
double num1 = 0.0;
boolean interruptor = true;
while(interruptor) {
try {
System.out.println("Introduce un real (con .)");
num1 = sc.nextDouble();
System.out.printf("Has introducido: %f\n", num1);
interruptor = false;
} catch (InputMismatchException e) {
System.out.println("No has introducido un real");
} finally {
sc.nextLine();
}
}
}