Help with writing code in a different way ( If with and "&")
Rob Michaelson
Ranch Hand
Joined: Jul 15, 2003
Posts: 36
posted
0
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
Joined: Jun 23, 2003
Posts: 1376
posted
0
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
Joined: Jul 15, 2003
Posts: 36
posted
0
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
Joined: Jun 23, 2003
Posts: 1376
posted
0
I'm doing great, Rob, thanks for asking! Good luck on your assignment. Joe
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Help with writing code in a different way ( If with and "&")