Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java enquiry!!

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java enquiry!!

    for(int i=0;i<20;i++){
    if(i>randomPosition -4 && i<randomPosition +4 && i!=randomPosition) i don't understand this part. Especially when i change to != to ==, the code will run wrongly, isn't both of their the same operator?

    System.out.print(" 0 ");
    else System.out.print(a[i] +" ");
    }
    }


    This will generate array with the left and right value reset to 0 so let say the random position is 5
    the output will be 4 2 0 0 0 6 0 0 0

    can anyone explain? Thanks.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,043
    My Mood
    Mellow
    Thanks
    184
    Thanked 648 Times in 635 Posts

    Default Re: Java enquiry!!

    Please post your code correctly using code or highlight tags which are explained near the top of this link.

    No, the two operators are not the same. Refer to Java operators.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java enquiry!!

    Quote Originally Posted by GregBrannon View Post
    Please post your code correctly using code or highlight tags which are explained near the top of this link.

    No, the two operators are not the same. Refer to Java operators.
    Thanks for replying. I had checked the java operator and they're the same?

    quote from java website link you posted
    equality == and !=

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,043
    My Mood
    Mellow
    Thanks
    184
    Thanked 648 Times in 635 Posts

    Default Re: Java enquiry!!

    So if you look at that table and see the entry:

    Additive: + -

    That means that the operators + and - are the same? You know better, right? Can you apply that same knowledge or pattern recognition and determine the difference between == and !=?