Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
Like Tree2Likes

Thread: What are the values of first and second at the end of the following code?

  1. #21
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: What are the values of first and second at the end of the following code?

    I find it all a bit strange that my knowledge or lack there of is so intriguing to you all. On a Java forum, I figured I could ask for help. I've only been in this class for a few weeks. Now-a-days, when students are in a hard class, they normally just try to ride it out together, but when my other classmates and I reach out to Google (very helpful) or lay off the assignment, and the professor is hard to understand, what am I supposed to do? I reviewed the slides, and actually put off coming here, trying to understand. In my other posts, I needed helps with parts of programs, so I'm not all that dumb. If I am, please don't judge me.

  2. #22
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,096
    Rep Power
    4

    Default Re: What are the values of first and second at the end of the following code?

    All good, but what do you have so far? I gave you a partial example for you to complete.

  3. #23
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: What are the values of first and second at the end of the following code?

    Quote Originally Posted by manibby93 View Post
    when students are in a hard class, they normally just try to ride it out together
    That has been true always - but excellent, teamwork is the way to go.

    , but when my other classmates and I reach out to Google (very helpful) or lay off the assignment, and the professor is hard to understand, what am I supposed to do?
    Read a bleeping book on Java!

    I have had a long history of sucky teachers in each and every programming class I've ever followed; each and every one of them knew only half about what they were teaching. I still passed with high grades since it doesn't matter in the slightest; it is all personal study (or in a study group). You don't learn programming by sitting in a classroom, you learn it by making the effort. Lots and lots of effort. Hours per day of it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #24
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,039
    Rep Power
    6

    Default Re: What are the values of first and second at the end of the following code?

    Quote Originally Posted by JosAH View Post
    Hint: it's an old trick to swap the value in those two variables without using a third variable.
    So do you also remember this?

    Java Code:
    int first = 8;
    int second = 19;
    first ^= second;
    second ^= first;
    first ^= second;
    System.out.println(first + "  " + second);
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #25
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: What are the values of first and second at the end of the following code?

    Quote Originally Posted by jim829 View Post
    So do you also remember this?

    Java Code:
    int first = 8;
    int second = 19;
    first ^= second;
    second ^= first;
    first ^= second;
    System.out.println(first + "  " + second);
    Regards,
    Jim
    Yep, that one is even better because some (old) hardware interrupted the processor when the addition of two ints overflowed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #26
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,039
    Rep Power
    6

    Default Re: What are the values of first and second at the end of the following code?

    Ok, time for some baby steps. First, do you know the answers to the following?
    Java Code:
    int first = 8;
    int second = 19;
    first = first + second;
    Two questions:
    1. Now what is the value of first?
    2. How can I modify the last line using one of the arithmetic assignment operators
    (Operators (The Java™ Tutorials > Learning the Java Language > Language Basics))

    If you know the answer to question 1, then you need to go do what Jos recommended using paper and pencil. Basically, you will play computer and determine the final values of first and second at the end of the exercise. Then if you notice how they have changed you can answer the other question. You can then alter the series of statements (where appropriate) using the answer to question 2 above.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #27
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: What are the values of first and second at the end of the following code?

    Teamwork for us is copying each others' answers because only like two people are majors in the course.
    Anyways, I DON'T read, especially being that I'm taking 6 classes. I don't mean that literally, but only one of them requires reading, because the other professors said we don't need a book for their class, verbatim. Anyways, I'm a COSC minor, and I wasn't planning on learning DrJava. Visual Basic was easier for me because I took two classes on it in high school too. Plus, the book told us all the formulas. With Java, I swear there are like a billion possible errors, all unnecessarily wordy. Just let me compile!!

  8. #28
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: What are the values of first and second at the end of the following code?

    Btw, I quit this assignment. I did 14/15, w/ Google's help. Thanks.

  9. #29
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,096
    Rep Power
    4

    Default Re: What are the values of first and second at the end of the following code?

    Reading your last two replies make me feel uncomfortable. So that's where I (we!) put in the effort for. Apparently you are a master of CTRL-C/CTRL-V and suck at programming in general. Correct me if I'm wrong. You should give up on any CS study.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 14
    Last Post: 01-22-2011, 03:36 PM
  2. HashMap contains all values but doesn't show all values
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 05-11-2009, 12:35 AM
  3. Replies: 3
    Last Post: 12-10-2008, 02:38 AM
  4. Replies: 0
    Last Post: 05-22-2008, 11:53 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
  •