LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   java newbie (https://www.linuxquestions.org/questions/programming-9/java-newbie-69662/)

stephenk 07-02-2003 05:21 PM

java newbie
 
I am writing a java program with arraylist

for (int i = 0; i < Width; i++) {
myRect.add(new MyRect(a,b,c,d,r,z));
z += 1;
}

for (int i = 0; i < myRect.size(); i++) {
MyRect m = (MyRect)myRect.get(i);
System.out.println(m);
}

what i am trying to do is creating a myRect class object, all of them have the same a,b,c,d,r, except z, each myRect class is increment by 1, however, when i will to println those values out
i got all my z's to be a same number. doesn't anyone know why and how to tackle it. thanks

zmedico 07-02-2003 05:56 PM

Re: java newbie
 
Quote:

Originally posted by stephenk

for (int i = 0; i < Width; i++) {
myRect.add(new MyRect(a,b,c,d,r,z));
z += 1;
}

z going into the constuctor is "pass by value" so the bug must be inside class MyRect. Post that code if you can't find the bug.

moeminhtun 07-02-2003 09:25 PM

edited.


All times are GMT -5. The time now is 11:05 PM.