Last active
December 15, 2015 11:39
-
-
Save KingSirLee/5254663 to your computer and use it in GitHub Desktop.
交换输入的两个数字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Exchange{ | |
public static void main(String[]args){ | |
java.util.Scanner input=new java.util.Scanner(System.in); | |
System.out.println("请输入两个数字:"); | |
int num1=input.nextInt(); | |
int num2=input.nextInt(); | |
System.out.println("现在顺序为"+num1+" "+num2); | |
int c=num1; | |
num1=num2; | |
num2=c; | |
System.out.println("交换过之后为"+num1+" "+num2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Exchange{ | |
public static void main(String[]args){ | |
java.util.Scanner input=new java.util.Scanner(System.in); | |
System.out.println("请输入两个数字:"); | |
int num1=input.nextInt(); | |
int num2=input.nextInt(); | |
System.out.println("现在顺序为"+num1+" "+num2); | |
int c=num1+num2; | |
num1=c-num1; | |
num2=c-num2; | |
System.out.println("交换过之后为"+num1+" "+num2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Exchange{ | |
public static void main(String[]args){ | |
java.util.Scanner input=new java.util.Scanner(System.in); | |
System.out.println("请输入两个数字:"); | |
int num1=input.nextInt(); | |
int num2=input.nextInt(); | |
System.out.println("现在顺序为"+num1+" "+num2); | |
num1=num1^num2; | |
num2=num1^num2; | |
num1=num1^num2; | |
System.out.println("交换过之后为"+num1+" "+num2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment