Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Method that returns true if string starts or ends with variance of word?

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
}

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here you go:

public static boolean startsOrEndsWithJava(String phrase) {
    phrase = phrase.toLowerCase();
    return (phrase.startsWith("java") || phrase.endsWith("java"))
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading