Results 1 to 11 of 11
Thread: Previous Exam Questions has me..
 05122011, 07:18 AM #1Member
 Join Date
 Nov 2010
 Posts
 90
 Rep Power
 0
Previous Exam Questions has me..
Looking at a past exam and a question has me stumped...
Given that x and y are both variables of type in, the statemennts:
y = x + x;
y += y+y;
are equivilent to
a) y= 2 * x;
b) y = 4 * x;
c) y = 6 * x;
d) y = 8 * x;
i have no idea how this works out.. all i can guess is A because there is 2 x's
if somoene could help and explain how this works it would be appreciated.
thanks
 05122011, 07:26 AM #2
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 9
Is the question, what will the final value of y be after these two expressions? I'd like you to try to think through it and see what you think it is. First calculate y in the first statement, then use the second statement to calculate the changed y. Show us your work and we will help you out.
 05122011, 07:29 AM #3Member
 Join Date
 Nov 2010
 Posts
 90
 Rep Power
 0
 05122011, 07:32 AM #4Senior Member
 Join Date
 Feb 2011
 Location
 Georgia, USA
 Posts
 122
 Rep Power
 0
set x equal to a number for instance 2
y = 2 + 2 = 4
plug in the values for y
y += 4 + 4 = 12 (you are summing the expression (4 + 4 = 8) with the value of y (4) because of the += operator
you should be able to figure out the rest
 05122011, 07:32 AM #5
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 9
Let's make up our own values. Solve for x = 2. After solving for x is 2 you will have an answer and you can verify it by using different values of x, perhaps the do x= 3,4,5,6,7,etc.
 05122011, 07:32 AM #6
 05122011, 07:35 AM #7Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
The "rules" are tiresome but everything has to be defined! If the result you get doesn't correspond to your intuition the JLS section 15.26.2 Compound Assignment Operators might (or might not) prove useful.
 05122011, 07:36 AM #8Member
 Join Date
 Nov 2010
 Posts
 90
 Rep Power
 0
ooooo i think i got it...
y = 6 * x;
SO.... if x = 10;
y = x + x;
y += y+y;
is
y = 10 + 10 ...y = 20
20 + (20+20)... 20 + 40.. is 60
or..
y = 6 * 10;
 05122011, 07:38 AM #9
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 9
Yup, good job. If you are done, please mark your thread solved. If you have more questions feel free to ask more.
 05122011, 07:38 AM #10
Yeah, most of the question had nothing to do with Java and lots to do with algebra. Did you not do algebra at school?
 05122011, 07:42 AM #11Member
 Join Date
 Nov 2010
 Posts
 90
 Rep Power
 0
I have not been at school or touched anything more than basic addition in maths for over 10 years.
Will do Sundae, thanks to you and the others for the help :)
as soon as i wrote my first reply i was like Oh right i get it now. been a long week studying 3 assignments due and full time work and exams next week.. brain dead hehe
Similar Threads

next and previous canot be same
By isme in forum New To JavaReplies: 0Last Post: 12152010, 02:05 AM 
Next and Previous Buttons
By kbgriggs in forum New To JavaReplies: 2Last Post: 08122009, 02:08 PM 
Exam Practice Questions
By AWPtic in forum New To JavaReplies: 24Last Post: 04182009, 03:50 PM 
Next and Previous Buttons
By JavaNewb in forum New To JavaReplies: 1Last Post: 05092008, 01:23 AM 
SCBCD 5.0 Mock Exam Questions
By kks_krishna in forum Reviews / AdvertisingReplies: 0Last Post: 04022008, 08:26 AM
Bookmarks