I am trying to compare two words and see if guess comes before word using compareTo()
while(!guess.equals(word)){
if(compare < 0){
System.out.println(word + " Comes before your guess. ");
detail();
} else if(compare > 0) {
System.out.println(word + "Comes after your guess. ");
detail();
}
}
System.out.println("You guessed it!");
s1.compareTo(s2)
is
s1
comes after s2
,s1
comes before s2
,s1
and s2
coincideSo, in your case you should
if(word.compareTo(guess) < 0){
System.out.println(word + " Comes before your guess. ");
detail();
} else if(word.compareTo(guess) > 0) {
System.out.println(word + "Comes after your guess. ");
detail();
}