Write a method that accepts a large string. This method will return true if the string starts with or ends with the word "Java". This word can be any variation with uppercase or lowercase letters.
java Java jAva jaVa javA JAva JaVa JavA jAVa jAvA jaVA JAVa JaVA jAVA JAVA are all of the possibilities.
public class Problem18 {
public static void main(String[] args) {
System.out.println(startsOrEndsWithJava("JavaTest")); // True
System.out.println(startsOrEndsWithJava("JaVaTest")); // True
System.out.println(startsOrEndsWithJava("TestJa va")); // False
System.out.println(startsOrEndsWithJava("TestJava")); // True
System.out.println(startsOrEndsWithJava("TestJAVA")); // True
}
public static boolean startsOrEndsWithJava(String phrase) {
// Your code here
}
}
>Solution :
Here you go:
public static boolean startsOrEndsWithJava(String phrase) {
phrase = phrase.toLowerCase();
return (phrase.startsWith("java") || phrase.endsWith("java"))
}