• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

first java am stuck

 
yoga nina
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have wasted all weekend trying to sort this out. If anyone can help i'd so appreciate it.
This is suppossed to be a leap year calculator. The values of the variables were given.
I thought I had worked it out all right but my if (and, or) staement keeps getting a error " bad operand types for binary operator ||"
I promise to read the FAQs when I have more time,
Cheers

 
Suhas Mandrawadkar
Ranch Hand
Posts: 72
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


R3 = 0 does not evaluate to a boolean. It is just an assignment.
'=' - assignment operator
'==' - equality operator.

Read more on operators - Equality, Assignment and Logical
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In your program line: you've got one too few "=" in your R3 comparison, so it is actually an assignment. This is a fairly common newbie error. One nice thing about Java is that it will catch this kind of error at compile time. In a language like C or C++, the assignment R3 = 0 will be treated logically as false no matter what value R3 had going into the expression. (It looks like you may have some other syntax errors in your code as well, but one at a time!)

By the way, one of the things the FAQ may mention is that you should surround your program excerpts in code brackets (you can use the button at the top of the message editor). That will display your code with formatting for easier reading.
 
yoga nina
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still stuck
Thanks guys but the missing = was just a silly typo on my part.
The message still comes up "illegal start of expression, bad operand types for binary operator ||, first type int, second type boolean"
I just don't get this as all my varaibles are int, the operators are boolean, but yeah so?
cheers, guys
will read FAQ in morning
 
Suhas Mandrawadkar
Ranch Hand
Posts: 72
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also have an extra "=" in "!==" and a semi colon at the end of line. It should be



Sorry, my bad. I could not point it out earlier
 
yoga nina
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Suha, you're a star.
All done, can get some rest now.
Bless you
 
Suhas Mandrawadkar
Ranch Hand
Posts: 72
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad, I could be of your help.
But please do read more on operators - Equality, Assignment and Logical. You got all of them wrong together in a single Line of Code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49364
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Confusing == and = is a very common mistake.
 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this example might be useful.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic