160k views
4 votes
Write a static method startsWith that inputs two Strings and returns a boolean. If the first input starts with the substring that is the second input, then the method returns true; otherwise, it returns false. For example, startsWith( "radar installation", "rad" ) returns true startsWith( "radar installation", "installation" ) returns false startsWith( "radar installation", "" ) returns true startsWith( "", "a" ) returns false startsWith( "", "" ) returns true

User Peter Fox
by
5.6k points

1 Answer

3 votes

Final answer:

The startsWith method in Java can be used to determine if the first input starts with the substring that is the second input.

Step-by-step explanation:

To determine if the first input starts with the substring that is the second input, you can use the startsWith method in Java. This method is available for string objects and returns a boolean value. Here is an example implementation:

public static boolean startsWith(String input1, String input2) {
return input1.startsWith(input2);
}

In this example, the startsWith method is called on the first input (input1), passing the second input (input2) as the argument. The method returns true if input1 starts with input2, and false otherwise.

User Redanthrax
by
6.0k points