I just want to compare the first word of two strings if they do not matter or not ...
Example:
String1="No puedo comparar"
String2="Si puedo comparar"
I would have to give false since the SI
and the NO
are not equal.
String1="Si puedo comparar"
String2="Si podre comparar"
I would have to give true since the Si
and the SI
are equal.
You have to ask for the value of the string by keyboard, then this is the part of the code that I have, but when I execute it, it always gives me that they are the same, so write different things, what's wrong?:
import java.util.Scanner;
public class comparacion{
String cadena1=("");
String cadena2=("");
String cadena1Array[]=cadena1.split(" ");
String c=cadena1Array[0];
String cadena2Array[]=cadena2.split(" ");
String c2=cadena1Array[0];
}
import java.util.Scanner;
public class main {
public static void main(String[] args) {
comparacion q=new comparacion();
System.out.println("Ingrese primera frase");
//llamado a la clase comparacion
Scanner read=new Scanner(System.in);
//Metodo de lectura de la variable cadebna 1
q.cadena1=read.nextLine();
System.out.println("Ingrese segunda frase");
Scanner read2=new Scanner(System.in);
q.cadena2=read2.nextLine();
//Quitar equals y comparar dos palabras iguales.
if(q.c.equals(q.c2)){
System.out.println(q.c);
System.out.println(q.c2);
System.out.println("Eureka");
}
}
}