posted 22 years ago
thanks roy for that array method once again but its clumsy(i am searching for a clean way, there is almost always a clean way in oops),however it solves my problem.
now let me put my question clearly for those people who are still missing the point.
class HowToSwap
{
public static int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; // r they enough ?
/* suppose i want to write a static function that will swap contents of any of these two variables ???*/
public void swap(int x,int y)// i know that this func doesnot work so dont waste your
// time in explaining why it doesnot work just give me somithing that works
{
int t=x;
x=y;
y=t;
return;
}
void main bla bla bla (bla)
{
swap(a,z); // here i want that actual contents actually should be swapped;
}
}
if still u dont understand my question.
let me put it in other way.
i am giving u 'C++' code give me its java equivalent which just swaps .
class ICanSwap
{
public:
static int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; // assume they r initialized some where else
public void swap(int &x,int &y)
{
int t=x;
x=y;
y=t;
return;
}
}
void main()
{
ICanSwap s;
s.swap( ICanSwap.a,ICanSwap.z); they r actually swaped
}
now dont tell me that java being platform independent,bla bla bla bla Language cannot perform some stupid swapping of variables thru functions.
and please give me some code that works and just dont tell me that, use objects or use wrapper classes, because i have tried everything but all in vain.
I will regard any person who answers this query as a true java guru.(Roy Ben Ami is close, for array method (the only method that works for now))
p.s. ( i still have a hunch that it cannot be done in java or am I underestimating THE language ? )
[ February 20, 2002: Message edited by: Jigar Gosar ]
[ February 20, 2002: Message edited by: Jigar Gosar ]