Question
Write a program named SubstringTester which prompts the user to enter two strings and uses the indexOf method of the String class to report whether
Write a program named SubstringTester which prompts the user to enter two strings and uses the "indexOf" method of the String class to report whether the second string is a substring of the first string.
Enclose the strings in quotes as shown in the sample output below. Be sure that your program accepts strings with embedded spaces.
Section 4.4.9 in the text describes finding characters and substrings in a Java String and provides examples of using the indexOf method.
Note: You must use the "indexOf" method for your solution in order to receive credit for this assignment. Yes, there are other methods to extract and test for substrings, but for this assignment this is the method you need to use.
As always, follow the guidelines presented in the Programming Assignment rubric, including an ID header, descriptive comments, correct code alignment, and camelCase notation for multi-word variables.. Submit only your .java file, do not submit a project, .class file, or program output.
You may submit an unlimited number of times up to the due date, but only your last submission will be graded.
Expected Output (user input is shown in red). Make sure your program produces this output given the example user input. Feel free to test additional input values to thoroughly test your program.
Please enter a string: quick brown fox Please enter another string: brown fox "brown fox" is a substring of "quick brown fox"
Please enter a string: quick brown fox Please enter another string: red rabbit "red rabbit" is not a substring of "quick brown fox"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started