Fixed it. Working code! I had to move the fruit array into the method and call it from main.
import java.util.Scanner;
public class StringArrayTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input;
System.out.println("Enter a fruit: ");
input = sc.nextLine();
System.out.println("Is \"" + input + "\" in the array? " + isIn(input));
sc.close();
}
public static boolean isIn(String input) {
String[] fruit = new String[6];
fruit[0] = "grape";
fruit[1] = "banana";
fruit[2] = "apple";
fruit[3] = "mango";
fruit[4] = "watermelon";
fruit[5] = "orange";
for(int i = 0; i < fruit.length; i++) {
if (input.equals(fruit[i])) {
return true;
}
}
return false;
}
}
mainmethod...that should suffice for now.