RECURSIVIDAD CON VOCALES
Publicado por Pris (4 intervenciones) el 06/08/2017 20:47:19
TENGO QUE HACER UN PROGRAMA DONDE EL USUARIO INGRESE UN TEXTO Y EL SISTEMA LE DIGA LA CANTIDAD DE VOCALES Y CUALES SON DE FORMA RECURSIVA. TENGO ESTA LINEA DE CODIGO Y ME LOGRA DECIR CUANTAS VOCALES HAY PERO NO CUALES SON, ALGUIEN PODRIA AYUDARME POR FAVOR
CODIGO:
CODIGO:
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
public static int vocales(String cad) {
if (cad.length() == 0) {
return 0;
}
switch (Character.toLowerCase(cad.charAt(cad.length() - 1))) {
case 'a':
return 1 + vocales(cad.substring(0, cad.length() - 1));
case 'e':
return 1 + vocales(cad.substring(0, cad.length() - 1));
case 'i':
return 1 + vocales(cad.substring(0, cad.length() - 1));
case 'o':
return 1 + vocales(cad.substring(0, cad.length() - 1));
case 'u':
return 1 + vocales(cad.substring(0, cad.length() - 1));
}
return 0 + vocales(cad.substring(0, cad.length() - 1));
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Ingrese el texto");
String cadena = sc.nextLine();
System.out.println("vocales:" + vocales(cadena);
Valora esta pregunta


1