The tests given are not equivalent.

This test;

if (n < 0  ||  n != 0) {
        // n is not zero
} else {
        // n is zero
}

But the test above can be simplified to;

if (n != 0) {
        // n is not zero
} else {
        // n is zero
}

this following test is a completely different test (if it equals zero in the
latter case it's the same as less than zero, in the other two cases the only
time the else case is met, is when n == 0;

if (n >= 0) {
        // n is zero or less
} else {
        // n is a positive value
}

regs
scot.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 27 November 2002 04:15
To: JDJList
Cc: [EMAIL PROTECTED]
Subject: [jdjlist] Re: In Java is this a valid expression (if( n <\<> 0 ))


No. I'm assuming you are trying to say "if (n is less than or not equal to
0)...."
You can try this instead:

  int n={some integer};

  if (n < 0  ||  n != 0)
    System.out.println("foo happens here");
  else
    System.out.println("bar happens here");

However, a clearer way to code it is this:

  if (n >= 0)
    System.out.println("bar happens here");
  else
    System.out.println("foo happens here");

Best regards,
Valerie Grunsted
[EMAIL PROTECTED] ____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to