import java.util.Scanner; public class Test1 { //1,两个变量里的数字进行交换,不依赖第三个变量 int a ; int b; public void swap(int a,int b){ a = a + b; b = a - b; a = a - b; System.out.println("交换后"+"a:"+a+",b:"+b); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Test1 t1= new Test1(); System.out.println("请输入两个数:"); t1.swap(scanner.nextInt(),scanner.nextInt()); } }