Results 1 to 7 of 7
  1. #1
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Conditional operaters in the if statment

    Is it possible to use an equation on both sides of the conditional operater in one line of the if statement?

    For example


    Java Code:
    if (x == 0 || x > 0)
     ..........;
    I'm looking for simplicity

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: Conditional operaters in the if statment

    Quote Originally Posted by Fubarable View Post
    What happens when you try this?
    I mean instead of having to add an if else parameter.

  4. #4
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: Conditional operaters in the if statment

    Quote Originally Posted by jwl View Post
    Is it possible to use an equation on both sides of the conditional operater in one line of the if statement?

    For example


    Java Code:
    if (x == 0 || x > 0)
     ..........;
    I'm looking for simplicity
    OK, I found out that this works

    Java Code:
    if (x > 0) x = 0;
    system.out.println();
    Now how would you add an if else line without printing the string in the above example.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Conditional operaters in the if statment

    Really not sure I understand what you're trying to achieve?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Conditional operaters in the if statment

    Quote Originally Posted by jwl View Post
    OK, I found out that this works

    Java Code:
    if (x > 0) x = 0;
    system.out.println();
    Now how would you add an if else line without printing the string in the above example.
    What does "works" mean? In other words, what is that pair of lines supposed to do?

    It's never enough to shut the compiler up. (And, in fact, its messages are annoyingly persistent but intended to be helpful). For code to work it must do precisely what we say it is intended to do.

  7. #7
    jwl
    jwl is offline Member
    Join Date
    Jul 2012
    Posts
    93
    Rep Power
    0

    Default Re: Conditional operaters in the if statment

    The operation I was looking for is

    Java Code:
    if (x => 0)
    If x is greater than or equal to zero.

Similar Threads

  1. Syntax Error in If statment
    By robinsonth@gmail.com in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 01:40 AM
  2. Missing Return Statment, HELP PLEASE.
    By dburgess in forum New To Java
    Replies: 2
    Last Post: 06-05-2011, 07:40 PM
  3. If statment not working:(
    By Harris68 in forum Networking
    Replies: 6
    Last Post: 02-24-2010, 10:41 PM
  4. statment replay!!!
    By moamen in forum New To Java
    Replies: 4
    Last Post: 09-25-2009, 12:49 PM
  5. Issue using FOR statment with NetBeans
    By Deathmonger in forum Advanced Java
    Replies: 3
    Last Post: 07-30-2008, 12:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •