Write a java program that reads two sentences as
strings, the program should print the common terms in both
sentences
example:
input:
I did my java homework yesterday
yesterday i went to java island
class Main {
public static void main(String[] args) {
String str1 = "I did my java homework yesterday";//first sentence
String str2 = "yesterday i went to java island";//second sentence
String[] temp = str1.split(" "); //split the first string by space and store in string array temp
System.out.println("Common terms are: ");
//prints the Common terms
for(String word : temp){
if(str2.contains(word))
{
System.out.println(word);
}
}
}
}
Output::
Get Answers For Free
Most questions answered within 1 hours.