Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

first java am stuck

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 72
Android Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74632
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Confusing == and = is a very common mistake.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope this example might be useful.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic