![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
hrmph, can't edit my posts...
umm, I have another technical question... I had a bunch of processes which I wanted to repeat, so I put them in a while loop, however I kept on getting an 'array index out of bounds' exception, I was stuck on it for a long time last night, trying to find the problem. Today I was talking about it with someone at uni and he suggested I change the while loop to another kind of loop, I just changed it to a for loop, and it worked. Is there something in while loops other than what they do that was causing the exception? Or am I just going insane, and sleep and some time off from the computer helped me get the thing to work... |
|
|
|
|
|
#12 |
|
Professional Programmer
|
Well , it depends on how you set up your while. It all comes down to the condition you put in while(condition) {}.
I don't see why it wouldn't work with while. You have in a previous example while ( x < 26;)
{
System.out.print(correct[x]);
} . So next time:while ( x < 26;)
{
System.out.print(correct[x]);
x++;
}
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#13 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
About your x y question on int variables.
If you have x = 5, y = 10 then do x = y; x = 10, y = 10, now if you do y = 15; x = 10, y = 15 Basicly these types of variables (primitives) store there value with the variable name in memory. Objects on the other hand point to there values(referenced), so if you have obj x = 'ex1', obj y='ex2' x = y (this makes them point to the same place in memory) x = 'ex2', y = 'ex2' Any change made to one, changes the other. x = 'ex1' x = 'ex1' y = 'ex1' |
|
|
|
|
|
#14 | |
|
Expert Programmer
|
Quote:
In your example, x = y makes x and y point to the same object in memory, not the same place in memory. In additon, setting one of the variables to a new object will not affect the other as they no longer point to the same object in memory. Any changes made to the object that both x and y are pointing to after assigning x = y will be reflected in both variables (for example, x.setAttribute(newvalue)), but reassigning one of the variables to another object (for example, x = new Object()) will not affect the other. You would benefit from reading the article I referred to in a previous post, Java is Pass-By-Value, Dammit!. |
|
|
|
|
|
|
#15 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3
![]() |
IIRC (I didn't read the article so I don't know if it covered this), Java will copy the value of primitives, but then do as you mentioned with Objects. So for the example using ints, changing one will not affect the other.
|
|
|
|
|
|
#16 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
@titaniumdecoy
You are right, and much better at wording what was going through my head. lmao. Ignore my post |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|