This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with writing code in a different way ( If with and "&")

 
Rob Michaelson
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am trying to change this code in another way (Don't worry , its not a homework question)
In particular I would like to split upi the "&" or get rid of it some how
Any suggetions?

Thanks
Rob
 
Joe Pluta
Ranch Hand
Posts: 1376
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob!
I'm not sure I understand the question. Why are you trying to get rid of the ampersand? Are you trying to avoid calling the getInt() method twice? If so, use a temporary variable.
Also, the single ampersand is a bitwise AND operator; you should use the double ampersand (&&) to logically AND together two boolean expressions. Anyway, depending on what you are trying to do, you could do the following:

However, this is a problem because "i" really can't be both less than zero and greater than 255 at the same time, so I think we may be missing something here. How about a little more detail on what you are trying to accomplish?
Joe
 
Rob Michaelson
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joe!!
I was just curious if there was another way of writing it - I saw a classmate's code and it looks every bit like mine... we do have explicit instructions but....
I can see what you mean though
How are you doing?
Rob
 
Joe Pluta
Ranch Hand
Posts: 1376
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing great, Rob, thanks for asking! Good luck on your assignment.
Joe
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can turn this around a bit:

I generally only trust this in my head if I know input1 is not null. Cause if a null slips by the first test it will cause a null pointer exception in the second. As mentioned above you are calling getInt() twice, which is common enough but still offensive to some.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic