Hello the problem says like this:
Create a class whose main method executes a letter-by-letter comparison using two-word equals using loops.
For example, if the words are
“avispa”
and“ave”
the program should result in:
Letter 1 equal in the two words?True
.
Letter 2 equal in the two words?True
Letter 3 equal in the two words?False
Letter 4 equal in the two words?La palabra 2 no tiene letra 4
Letter 5 equal in the two words?La palabra 2 no tiene letra 5
Letter 6 equal in the two words?La palabra 2 no tiene letra 6
.
I try it this way (I clarify that it must be object oriented):
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Introduce palabra 1: ");
Entrega662 cadena1=new Entrega662();
System.out.println("Ingrese palabra 2: ");
Entrega662 cadena2=new Entrega662();
if(cadena1.getLargo()>cadena2.getLargo()){
boolean iguales;
for(int x=0;x<cadena1.getLargo();x++){
System.out.println("¿Letra "+(x+1)+" igual en las dos palabras");
if(cadena1.getLetra(x).equals(cadena2.getLetra(x))){
iguales=true;
System.out.println(iguales);
}else{
iguales=false;
System.out.println(iguales);
}
if(x>cadena2.getLargo()){
System.out.println("Cadena 2 no tiene letra "+(x+1));
}
}
}
Look at the result you give me:
Introduce palabra 1: Avispa Ingrese palabra 2: Ave ¿Letra 1 igual en las dos palabras true ¿Letra 2 igual en las dos palabras true ¿Letra 3 igual en las dos palabras true ¿Letra 4 igual en las dos palabras true ¿Letra 5 igual en las dos palabras true Cadena 2 no tiene letra 5 ¿Letra 6 igual en las dos palabras true Cadena 2 no tiene letra 6