Thursday, 27 November 2014

Program in java to find a String in a sentence

Hi all
I am writing a program to find whether a particular word exists in a sentence or not .


public class SB

{

public static void main(String[] args) {
String test="Hi I am here";
String find="am";

if(test.indexOf(find)>0)
{
System.out.println("found ");
}
else
{
System.out.println("not found");
}
}


}


output: found

------------------------------------------------------------------------------------


public class SB

{

public static void main(String[] args) {
String test="Hi I am here";
String find="kill";

if(test.indexOf(find)>0)
{
System.out.println("found am");
}
else
{
System.out.println("not found");
}
}


}

output : not found

No comments:

Post a Comment