Answer:
Scanner scan = new Scanner(System.in);
System.out.println("Enter 2 strings:");
String word1 = scan.nextLine();
String word2 = scan.nextLine();
//equal strings
if (word1.equals(word2))
{
System.out.println("Equal!");
}
//same word, different case
else if (word1.toLowerCase().equals(word2.toLowerCase()))
{
System.out.println("Different case");
}
//same up to the last letter
else if (word1.substring(0, word1.length()-1).equals(word2.substring(0, word2.length()-1)))
{
System.out.println("Close enough");
}
//no equivalency
else
{
System.out.println("Try again");
}
Step-by-step explanation:
got 100% on the assignment so the code is correct
first scenario: both strings are equal, including the casing
second scenario: by setting both strings to lowercase if their cases don't match, they can be interpreted as having the same value by those standards in order to print out the statement
third scenario: .length() - 1 equates to the last letter of a string, so starting the range at 0 and ending at that will be read as the first letter to the letter before the last letter
fourth scenario: the strings do not fit into anything previously evaluated