• Post Reply Bookmark Topic Watch Topic
  • New Topic

bad operand types  RSS feed

 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on this problem for a while now and continue to get an error when I try to subtract
one user inputted integer from another. It seems to compile fine for adding, dividing, and multiplying.
Can someone please explain why it might be making that error and how to resolve it? (As an aside,
I have no idea if I did the whole program right but am just trying to figure out why a declared int
would come back with an error it's a string.)

Thanks for any tips or suggestions.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: operator precedence
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint 2: Always include the exact text of the error message including line numbers.
 
luke gu
Greenhorn
Posts: 2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
case 2:
System.out.println("Your total is " + firstInt - secondInt);
it should be :
case 2:
System.out.println("Your total is " +( firstInt - secondInt));
 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Hint 2: Always include the exact text of the error message including line numbers.


Sorry about that. After I posted it I figured I should have done so.

Thanks for the responses.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Details of the + operator applied to Strings here. You will have realised that by the time you reach the − operator, you have the String "Your total is 123" as its left operand.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!