CADENA DE PALABRAS
EJERCICIO "2"
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cadenapalabra;
import java.util.Scanner;
public class CadenaPalabra {
public static void main(String []args){
Scanner teclado = new Scanner(System.in);
System.out.print("INGRESA TU PRIMERA FRASE: ");
String ca=teclado.nextLine();
System.out.print("INGRESA TU SEGUNDA FRASE: ");
String ca1=teclado.nextLine();
System.out.print("INGRESA TU TERCERA FRASE: ");
char c=teclado.next().charAt(0);
int repeticion=0;
char []caracter=ca.toCharArray();
for(int i=0;i<=caracter.length-1;i++){
if(c==caracter[i]){
repeticion++;
}
}
System.out.println("SE ENCONTRO LOS SIGUIENTES CARACTERES: "+repeticion+" EL CARACTER '"+c+"'");
int contador = 0;
while (ca.indexOf(ca1) > -1) {
ca = ca.substring(ca.indexOf(ca1)+ca1.length(),ca.length());
contador++;
}
System.out.println ("NUMERO DE VECES QUE SE REPITE LA CADENA /PALABRA/: "+contador);
}
}
No hay comentarios:
Publicar un comentario