Write a java program to match with word:
import java.util.Scanner;
public class CheckSpecifiedWord {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Sentence ");
String str = sc.nextLine();
System.out.println("Enter Substring : ");
String substr=sc.nextLine();
boolean rs=isMatchWord(str, substr);
if(rs) {
System.out.println("Matched");
}
else {
System.out.println("unmatched");
}
}
static boolean isMatchWord(String str,String substr) {
int j=0;
for(int i=0;i<str.length();i++) {
String temp="";
while(i<str.length() && str.charAt(i)!=' ') {
temp=temp+str.charAt(i);
i++;
}
System.out.println(temp);
System.out.println(substr);
if(temp.equals(substr))
return true;
}
return false;
}
}
Comments
Post a Comment