File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Bad operand types for binary operator? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Bad operand types for binary operator? " Watch "Bad operand types for binary operator? " New topic
Author

Bad operand types for binary operator?

Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Hi,
I am working on a program to make a program in which the user plays craps. I know there are more problems, as this is a work in progress, but first I need to complete public static boolean play before I can move forward. When I try to compile, I get an error message that says "bad operand types forbinary '||' first type: int; second type: boolean" while the compiler highlights "|| result ==11" what does this error message mean and can someone point me in the right direction of how to fix it? Or is it a simple fix that I am missing? Any help is GREATLY appreciated. I have banging my head on the wall over this one for a couple hours now.


Once again, I cannot give enough thanks for any help.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

Hello Brian Mart,

Welcome to CodeRanch!

So, below is the problematic line:

Here, you can easily see what is wrong here.

Hint : operator '||' requires both operands to be boolean. What is your first operand?

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Thanks Anayonkar, but aren't both of my operands "result"? I am new to Java so I am not entirely sure. If my operands are "result" why does the first one on that same line work just fine and the error message only appears on the second instance of result? Also, according to my instructions, result needs to be an int. So confused...
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

Ok.

Here's another hint : what's the difference between '==' and '='?

P.S. I'm giving you hints because it would be nice if you yourself understood what is wrong - instead of getting a ready-made answer. I hope you don't mind
Stanley Mungai
Ranch Hand

Joined: Dec 09, 2011
Posts: 155

You are comparing Different things if result =7|| result==4, One side of || contains an integer and the other side a boolean. Both sides need to be either....Got it now?


Give a beggar a fish; feed him for a day. Teach him how to fish; Feed him for a lifetime.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Stanley Mungai wrote: . . . Both sides need to be either....Got it now?
No, both sides must be “boolean”. It will work with a small b or a capital B because of un-boxing (since Java5 in 2004). The details are in the Java Language Specification, but they are slightly different for the | operator, which can take ints as operands.

Anyway, as has already been mentioned, the real error was confusing == and =.
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Thanks, it was just a simple oversight but the compiler message just confused me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bad operand types for binary operator?
 
Similar Threads
Need help at converting java program to pseudo code
calling a method w/out an object
Probability Question
Create a Die Class
Craps Game Code