Pages

Search character or word in a sentence using java

*****************************************************
COMPLETE SOURCE CODE FOR : SearchCharacterOrWordInASentence.java
*****************************************************


public class SearchCharacterOrWordInASentence
{
public static void main(String[]args)
{
//-1 mean the word or character that you search not exist

String a="Hello World !!!";

//SEARCH CHARACTER
int b=a.indexOf('H');
if(b!=-1)
{
System.out.println("H exist");
}

//SEARCH Hello IN Hello World !!!
int c=a.indexOf("Hello");
if(c!=-1)
{
System.out.println("Hello exist");
}
}
}


*****************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************
Related Posts Plugin for WordPress, Blogger...