-Previously - java class with one static method.
In the static method called beforeThis. take 2 strings as inputs and return a string.
Code for the method should look for 1st input String within the 2nd input, and return everything from 2nd input string that comes before.
ex: 1st input : "tennis"
2nd input : "A tabletennis is in the basement"
method returns: "A table"
Thanks for the question, below is the beforeThis static method
===================================================================== =
public static String beforeThis(String search, String text){ if(text.contains(search)){ return text.substring(0,text.indexOf(search)); } return text; }
===================================================================
// Here is the complete Java class
===================================================================
class TestProgram { public static String beforeThis(String search, String text){ if(text.contains(search)){ return text.substring(0,text.indexOf(search)); } return text; } public static void main(String[] args) { System.out.println(beforeThis("tennis","A tabletennis is in the basement")); } }
=================================================================
Get Answers For Free
Most questions answered within 1 hours.