• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Program but what's wrong???

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I get the value 0 when its ran, not 2. Why???
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I know that this works correctly, but why does it not work the other way???
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy to help!

Your problem boils down to one major "oops". In your class method that changes the color.... take a look... a CLOSE look at exactly WHAT is getting set with the value of what! Hint.... you are setting the value of the argument with the current value of the int. To research this part, look up some info on "assignment" and I think you'll find the key.

The reason that it works in the second example is that, in the same handler as above, you are returning the value of the argument that you passed in NOT the value of the int. It will always pass back what you passed in.

Read this, take another look at these areas, and I think you'll find your answer!

Best of luck.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Says, assign the current value of the variable anIntegerRepresentingColors to the variable newHue and then allow the newHue variable to fall out of scope.

What I think you want is:

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about that, it works now. thanks I overlooked that.
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic