方法一
public class Test2 {
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner (System.in);
System.out.println("简单数值交换小程序");
System.out.println("请输入第一个数值");
int a = input.nextInt();
System.out.println("请输入第二个数值");
int b = input.nextInt();
int c ;
c = a;
a = b;
b = c;
System.out.println("交换后第一个数的值为:" + a + " " + "第二个数的值为:" + b);
}
}
方法二
public class Test4{
public static void main (String[]args){
java.util.Scanner input = new java.util.Scanner (System.in);
System.out.println("请输入第一个函数值");
int a = input.nextInt();
System.out.println("请输入第二个函数值");
int b = input.nextInt();
a = b - a;
b = b - a;
a = a + b;
System.out.println("第一个函数值:" + a);
System.out.println("第二个函数值:" + b);
}
}