1 package com.test;
2 public class test1 {
3 public static void main(String[] args) {
4 int x = 10;
5 int y = 20;
6 int[] tempArr = swap(x,y);//定义数组接收返回值
7 x = tempArr[0];
8 y = tempArr[1];
9 System.out.println("x="+x+";y="+y);
10 }
11 public static int[] swap(int x, int y)//定义函数换值,返回数组
12 {
13 int[] arr = new int [2];
14 x = x ^ y;
15 y = x ^ y;
16 x = x ^ y;
17 arr[0] = x;
18 arr[1] = y;
19 return arr;
20
21 }
22 }