下面程序段运行后,变量x的值是多少?public static void swap(int a,int b){int t = a;a = b;b = t;}public static void main(String args[]){int x = 2;int y = 3;swap(x,y);}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 05:18:44
下面程序段运行后,变量x的值是多少?public static void swap(int a,int b){int t = a;a = b;b = t;}public static void main(String args[]){int x = 2;int y = 3;swap(x,y);}
xSOOA*SOn\Eogì%d\7X!fcEWMMq/33:3v1ċ{˼7gU3᷆c9er/2v^u{&*.ZV_mVZfD7_:XPlH'pnD(s+ yƈ)T`9E QVbۂB Y[͸f<gwp>,aw/I뻷wMn#ѝ"~|nVd) +&t=" W? f\rsńGAzNp_3A.6Y!œ,? 0R c,Jg9焗oX`,(s%],%N%gRa}ϦD/C4a'9dxz;n@QH WVѴܠƕ)#u,$n־-Rv"Se˄FpdL

下面程序段运行后,变量x的值是多少?public static void swap(int a,int b){int t = a;a = b;b = t;}public static void main(String args[]){int x = 2;int y = 3;swap(x,y);}
下面程序段运行后,变量x的值是多少?
public static void swap(int a,int b){int t = a;
a = b;b = t;}public static void main(String args[]){int x = 2;int y = 3;swap(x,y);
}

下面程序段运行后,变量x的值是多少?public static void swap(int a,int b){int t = a;a = b;b = t;}public static void main(String args[]){int x = 2;int y = 3;swap(x,y);}
值参数传递不能实现交换两个整数,所以你这里x最后还是2,要想实现两个值得交换可以已数组的形式实现,代码如下:
//实现个整数的交换
public class SwapInteger {
public static void swap(int a[]){
//数组传递实现交换两个整数
int t;
t = a[0];
a[0] = a[1];
a[1] = t;


}
public static void main(String args[]){

int []a = new int[2];
a[0] = 3;
a[1] = 4;
swap(a);
System.out.println(a[0] + "/t" + a[1]);
}

}
希望对你能有帮助!