Answer:
import java.util.*;
public class Lab7B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter first String");
String word1 = in.next();
System.out.println("Enter Second String");
String word2 = in.next();
System.out.println(compareLetters(word1,word2));
}
public static boolean compareLetters(String wrd1, String wrd2){
int len1 = wrd1.length();
int len2 = wrd2.length();
if(wrd1.charAt(0)==wrd2.charAt(0)&&wrd1.charAt(len1-1)==wrd2.charAt(len2-1)){
return true;
}
else{
return false;
}
}
}
Explanation: