Results 1 to 12 of 12
Thread: Studying for Finals
 01122013, 08:50 PM #1Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0

Re: Studying for Finals
It might be quicker to test this yourself first with your handy Java compiler. Then check out the JLS or Java Language Specification on Widening Primitive Conversion. as well as the next chapter on Narrowing Primitive Conversion.
Last edited by Fubarable; 01122013 at 09:07 PM.
 01122013, 09:06 PM #3Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0
Re: Studying for Finals
All I wanted to know if that statement was correct or not
 01122013, 09:07 PM #4Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0
Re: Studying for Finals
But i think i figured it out on my own...thanks

Re: Studying for Finals
 01122013, 09:27 PM #6Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0
Re: Studying for Finals
Ok now i have another question that I cant seem to solve...
Given the following code, where x=0, what is the resulting value of x after the forloop terminates?
for (int i=0; i<5; i++)
x += i;

Re: Studying for Finals
What happens when you write out what happens on paper? It will take at most 5 lines to do.
 01122013, 09:41 PM #8Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0
Re: Studying for Finals
Thats what I tried doing......
x i
0 0
0 1
1 2
3 3
6.....terminates....but thats not one of my answers...my answers are
a 0
b 4
c 5
d 10
e 15

Re: Studying for Finals
You may be forgetting that += will add the current number the number already held by x.
So if x = 20, then x += 15 will make x == to 35.
Edit: Ah, you may be doing your math wrong. Not
0 0
0 1
1 2
3 3
6.... terminate
but rather
Java Code:i x 0 0 1 1 2 3 3 6 4 10 terminate
Last edited by Fubarable; 01122013 at 10:03 PM.
 01122013, 10:02 PM #10Member
 Join Date
 Nov 2012
 Posts
 44
 Rep Power
 0
Re: Studying for Finals
I thought thats what I did?

Re: Studying for Finals
See edit above please.
 01132013, 03:21 PM #12Member
 Join Date
 Jan 2013
 Posts
 6
 Rep Power
 0
Re: Studying for Finals
for (int i=0; i<5; i++)
x += i;
Starting off with x = 0, and the formula is x += i
This formula means to keep adding the values of i on to the value of x.
Going through the values of 'i' up to 4 (because 4 is less than 5) here is what we get:
When i = 0:
0 + 0 = 0
When i = 1:
0 + 1 = 1
When i = 2:
1 + 2 = 3
When i = 3:
3 + 3 = 6
When i = 4:
6 + 4 = 10
Therefore the last value of x before the loop terminates is 10.
Similar Threads

Studying progress
By tnrh1 in forum Forum LobbyReplies: 2Last Post: 02252012, 10:10 PM 
Midterm studying
By Bgreen7887 in forum New To JavaReplies: 0Last Post: 03152011, 02:04 PM 
Studying Directions
By Deepwoods in forum New To JavaReplies: 3Last Post: 08192010, 08:53 PM 
Local Finals
By Drun in forum New To JavaReplies: 6Last Post: 11202009, 06:50 AM 
Need a tutorial for Studying about Panels
By ramachandran in forum New To JavaReplies: 1Last Post: 10252007, 09:05 AM
Bookmarks