Ask coding questions

← Back to all posts
Java: What am i doing that is preventing me using the code to check the user input against the list?
Dawson313 (0)

List:
ArrayList List = new ArrayList();
List.add("Add");
List.add("Subtract");
List.add("Multiply");
List.add("Divide");

Get User Input:
Scanner userInput = new Scanner(System.in);
System.out.println("What do you want to do?");
String user_choice = scanner.next();

Check Input Against List:
if (user_choice(List)); {
System.out.print("Working");

Comments
hotnewtop
Coder100 (18922)

extra semi right here

Dawson313 (0)

i removed it and it gave me:
 javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java
Main.java:19: error: cannot find symbol
String user_choice = scanner.next();
^
symbol: variable scanner
location: class Main
Main.java:21: error: cannot find symbol
if (user_choice(List)) {
^
symbol: method user_choice(ArrayList)
location: class Main
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
compiler exit status 1

@Coder100

Coder100 (18922)

you defined your scanner class to be userInput?

Scanner userInput = new Scanner(System.in);
      System.out.println("What do you want to do?");
      String user_choice = userInput.next();

please, read the errors lol
@Dawson313

Dawson313 (0)

that wasn't what i intended, i meant to set the name of it to userInput, i wanted the input to be string and to be able to reference it as userInput, i'll mess around with [email protected]

Dawson313 (0)

ok i think i have no idea what im doing with this scanner any [email protected]