So, pretty extreme newb. Just a heads up.
Here's the assignment that I'm working on:
Write a method that accepts a large string. This method will return true if the string starts 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 possibilites.
And this is the code that is given to start:
public class Problem16 {
public static void main(String[] args) {
System.out.println(startsWithJava("JavaTest")); // True
System.out.println(startsWithJava("JaVaTest")); // True
System.out.println(startsWithJava("TestJava")); // False
System.out.println(startsWithJava(" JavaTest")); // False
}
public static boolean startsWithJava(String phrase) {
// Your code here
}
}
And so far this is where I'm at:
public static boolean startsWithJava(String phrase) {
String[] java = {"java","Java","jAva","jaVa","javA","JAva","JaVa","JavA","jAVa","jAvA","jaVA","JAVa","JaVA","jAVA","JAVA"};
for (int i = 0; i < java.length; i++) {
if (phrase.substring(0, 3) == java[i])
return true;
}
}
So I'm thinking I need to figure out a different way to do it, because I'm having trouble figuring out how to properly get a boolean return statement outside of the for loop.
Appreciate the help in advance!