aspose file tools
The moose likes Beginning Java and the fly likes Incompatible operand types Scanner and int Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Incompatible operand types Scanner and int" Watch "Incompatible operand types Scanner and int" New topic
Author

Incompatible operand types Scanner and int

brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 32
I have a simple code such as



I assumed that the function nextInt would automatically assign choices as an int and if so why does my if statement say Incompatible operand types Scanner and int.

Also how would I do it if the Scanner input was a string and I want to say if (choices == attack) etc

Thanks!
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1
compare your code to the Scanner API

Scanner sc = new Scanner(System.in);
int i = sc.nextInt();

in your code you are comparing the Scanner itself to an int

SCJP
brent carter
Ranch Hand

Joined: Dec 15, 2011
Posts: 32
thanks randall...makes perfect sense. I am having a bit of trouble copying this to strings tho. for instance.



doesnt work. what is the difference here between ints and strings?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1778
You should use equals() method instead of == while comparing strings.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Incompatible operand types Scanner and int
 
Similar Threads
Calling a variable form the main class
Incompatible operand types Scanner and int
Enum or int
confusion in ==
Problem with Incompatible Types. Help appreciated, information much more so.