Java 交换两个变量的值

 1  //交换两个变量的值
 2        // 1
 3        int nu1 = 10;
 4        int nu2 = 20;
 5        
 6        System.out.println("nu1 = "+nu1+"\t"+"nu2 = "+nu2);
 7        
 8        int temp;
 9        
10        temp = nu1;
11        nu1 = nu2;
12        nu2 = temp;
13        
14        System.out.println("nu1 = "+nu1+"\t"+"nu2 = "+nu2);
15         
16         //2
17       // num1 = num1 + num2;
18       // num2 = num1 - num2;
19       //num1 = num1 - num2;
20       // System.out.println("nu1 = "+nu1+"\t"+"nu2 = "+nu2);
21        
22        
23        //3
24       // num1 = num1 ^ num2;
25       // num2 = num1 ^ num2;
26       // num1 = num1 ^ num2;
27       // System.out.println("nu1 = "+nu1+"\t"+"nu2 = "+nu2);
28         

Java  交换两个变量的值

 

上一篇:TypeScript基础学习


下一篇:变量类型