I am getting a weird error. it's claiming I don't have a if statement for my else statement. Here is the main code. Any help would be greatly appreciated.
public class MatchingString
{
private static String[] arr = {"Hello", "Karel", "CodeHS!"};
static int match = 1;
static int noMatch = 0;
public static int findString(String myString){
for (int i=0; i<arr.length; i++){
if (myString == arr[i]);
{
return match;
} else {
return noMatch;
}
}
return noMatch;
}
}
Here is the runner.
public class MatchingStringTester{
public static void main(String[] args){
System.out.println(MatchingString.findString("hello"));
}
}
and here is the error.
MatchingString.java:13: error: 'else' without 'if'
}else {
^
1 error
Aucun commentaire:
Enregistrer un commentaire