Question: Write a Java program from scratch that meets the following requirements: a . The program is in a file called Matching.java that defines a class
Write a Java program from scratch that meets the following requirements:
a The program is in a file called Matching.java that defines a class called
Matching.
b The program includes a Java method called find that takes two Strings and
returns an integer. If the second string does not appear in the first string, find
returns If the second string appears in the first string, find returns the index
of the character where the second string begins in the first string. Make sure the
method is public static.
example tests:
find returns
finda returns
findHello World", "World" returns
findWorld "Hello World" returns
findHello World", lo W returns
hint: you will find the length and charAt methods of String useful. To call them on a String x
you would do length and charAtiwhere is whatever index in the String you want to
get Alternatively to charAt, you could use toCharArray to get a char containing the
characters.
Java's String has a method indexof that does nearly the same thing as find; however, we do
not want you to use index of in your solution to this problem.
c The program's main method calls find on the above test cases and prints each
return value.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
