On Apr 22, 6:07 pm, Nguyễn Đình Đoàn <[email protected]> wrote:
> miga said that malti sharma added more println() method. It only displays
> and displays, here I want to display the result by own two println() methods
> in main(). No addition in swap. If that, nothing to say!
> It's OK but is not my requirement ^^!
>
> Maybe we can't do that, because when code *swap(int a, int b)*, then we
> indicate that *PASS BY VALUE => a, b can't be changed*
> I think swap(a, b) is impossible, must be swap() ^^! (too shy :p)
You may browse the url I gave above, there is the solution in it.
The principle is to initialize an array in main before swapping, which
will receive the result of swap(a,b). This will allow you to return
the two variables swapped in swap(a,b), as you cannot return multiple
values from a method unless you put them in a collection.
This way, the values in the main will really be swapped after return
from the method. Otherwise, you swap them in the method, but they
remain the same in the main.
This applies to any kind of object, not just integers.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---