hi!
I have program with 2 public classes and main.
I have decraded it as 'public int count =0;'
know I want to change value of it in class I call counter (with I call
from main), then pass it back to another class, who prints output.
main have loop with goes through aray list and prints output.
but I can't get correct value of count becouse it have to change
dependingly on with char is in array e.i. eather increase or decrease..
how to do it..
I hoppe you understand what I meana...

Signature
thanx in advance
______________________________
John McGrath - 09 Apr 2005 21:18 GMT
> I have program with 2 public classes and main.
> I have decraded it as 'public int count =0;'
[quoted text clipped - 4 lines]
> with char is in array e.i. eather increase or decrease.. how to do it..
> I hoppe you understand what I meana...
Sorry, no. If you post some code, it will probably be a lot more clear.

Signature
Regards,
John McGrath
iamfractal@hotmail.com - 10 Apr 2005 12:55 GMT
> hi!
>
[quoted text clipped - 7 lines]
> how to do it..
> I hoppe you understand what I meana...
(Deep breath.)
Hi, Carramba!
I'm guessing you have two classes something like these (ridiculous
example, I know, but it covers the points):
public class Main {
public int count = 0;
public static void main(String[] args) {
Counter counter = new Counter();
counter.ChangeThis(count);
for (int i = 0, n = count; i < n; i++) {
System.out.println("Args " + i + " = " + args[i]);
}
}
}
public class Counter {
public void changeThis(int count) {
count = count + 5;
}
}
This will not work because Java method parameters are pass-by-value,
and no modification of the count variable in the Counter class will
affect the value of the count variable in the Main class.
Here's the solution:
public class Main {
public int count = 0;
public static void main(String[] args) {
Counter counter = new Counter();
count = counter.getChangedValue(count);
for (int i = 0, n = count; i < n; i++) {
System.out.println("Args " + i + " = " + args[i]);
}
}
}
public class Counter {
public int getChangedValue(int count) {
count = count + 5;
return count;
}
}
.ed
www.EdmundKirwan.com - Home of The Fractal Class Composition