Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SubStringFinder {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- while(true){
- System.out.println("Enter String");
- final String stringToSearch = scn.nextLine();
- String givenString = stringToSearch.toLowerCase();
- boolean found = searchString(givenString);
- if(found){
- System.out.println("String Found");
- break;
- }//if
- else{
- System.out.println("String Not Found");
- }//else
- }//while
- }//main
- public static boolean searchString(final String givenString) {
- int indexNo;
- boolean found = false;
- int len = givenString.length();
- for(indexNo=0;indexNo<len;indexNo++){
- if(givenString.indexOf('h',indexNo) != -1){
- ++indexNo;
- if(givenString.indexOf('a',indexNo) != -1){
- ++indexNo;
- if(givenString.indexOf('r',indexNo) != -1){
- ++indexNo;
- if(givenString.indexOf('i',indexNo) != -1){
- ++indexNo;
- found = true;
- break;
- }//if
- }//if
- }//if
- }//if
- }//For
- return found;
- }
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement