File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help with writing code in a different way ( If with and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with writing code in a different way ( If with and "&")" Watch "Help with writing code in a different way ( If with and "&")" New topic
Author

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

Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
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
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
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
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
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help with writing code in a different way ( If with and "&")
 
Similar Threads
String to int
check variable.nextDouble() is a number not characters
resultset problem
cant find method from JOptionPane class
Understanding Comparator