Write a JAVA method that takes two references to two java variables and swaps their values.
السلام ...
لوسمحتم يا اخوان ممكن احد يساعدني في حل هذا السؤال والله حاولت بس ماعرفت احله ممكن احد يساعدني بحله وهذي محاولتي بس مادري اذا صحيحه ولا لا.
public class test
{
public static void swap(int[] a, int[] b)
{
int temp = a[0];
a[0] = b[0];
b[0] = temp;
}
public static void main(String[] args)
{
int[] x = new int[1];
int[] y = new int[1];
x[0] = 1;
y[0] = 2;
swap(x,y);
System.out.println("X ="+x[0]);
System.out.println("Y ="+y[0]);
}
}