本文主要是介绍Java 交换两个变量值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import java.util.Scanner;
public class myClass {
public static void main(String[] args) {
// TODO 自动生成的方法存根
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
System.out.println("Please input value of A : ");
long A = scan.nextLong();
System.out.println("Please input value of B : ");
long B = scan.nextLong();
System.out.println("A = " + A + "\t B = " + B);
System.out.println("exchange result: ");
A = A ^ B;
B = B ^ A ;
A = A ^ B ;
System.out.println("A = " + A + "\t B = "+ B);
}
}
这篇关于Java 交换两个变量值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!