What I have below is so far that I got but the problem is that if I enter something like "The people are angry" and then I enter to find the letters "pope" it returns false so I don't know where it is going wrong
public static void main(String[] args)//Driver method { Scanner input = new Scanner(System.in); System.out.println("This Program will check if the letters of the string is found in another string "); System.out.println("Enter a sentence"); String text = input.nextLine(); System.out.println("Enter the letters to see if the letter are in the first sentece "); String check = input.next(); System.out.println(containsInOrder(text, check));//Recursive method } public static boolean containsInOrder(String text, String check) { if (text.length() == check.length()) { return text.equals(check); } else return text.startsWith(check) || containsInOrder(text.substring(1) , check); }
So I expect the output to be true when the letter pope is found in the string the people are angry and false otherwise