Question
I need the Java code for the following: Write a program named SubstringTester which prompts the user to enter two strings and uses the indexOf
I need the Java code for the following:
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 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 comments, alignment, and camelHump for multi-word variables.. Submit only your .java file, do not submit a project, .class file, or program output.
Sample Output (user input is shown in red):
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