• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

if, else if, else trouble

 
Ranch Hand
Posts: 48
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am trying to compile this program and i keep receiving an error. I can't figure out what the problem is, perhaps I need another pair of eyes to look at it.
Anyways here is my code:



And here is the error message i get when i compile it via command prompt:


I've declared the variable num as an integer, why is it asking for boolean?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you know the difference between '=' and '==' in java? Note: java is different from C (if you are familiar with that language - if not, don't worry about it).
 
John Vorona
Ranch Hand
Posts: 48
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, i completely forgot about this. The program works properly now.

Just to clarify, in Java "==" means true equality, where as "=" is simply assignment?
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nazar Buko wrote:Right, i completely forgot about this. The program works properly now.

Just to clarify, in Java "==" means true equality, where as "=" is simply assignment?



Yes.
As for "==", it is mostly used to test equality between primitive types (e.g. int, char). equals() is used when testing the equality of objects (e.g. Strings and mostly everything). When used between objects, "==" only returns true if the left and right refer to the exact same object. The following would print false then true:

 
John Vorona
Ranch Hand
Posts: 48
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joel Christophel wrote:



I see, the first one would be false since x and y are different instances of the String object. Where as x.equals(y) simply means, x and y have the same values.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nazar Buko wrote:
I see, the first one would be false since x and y are different instances of the String object. Where as x.equals(y) simply means, x and y have the same values.


Correct.
 
John Vorona
Ranch Hand
Posts: 48
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all.
reply
    Bookmark Topic Watch Topic
  • New Topic