写一个java程序实现输入的值进行交换
时间: 2024-05-09 17:18:04 浏览: 49
Sure, here's a Java program to swap the values of two variables:
```java
import java.util.Scanner;
public class SwapVariables {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the first value: ");
int a = input.nextInt();
System.out.print("Enter the second value: ");
int b = input.nextInt();
System.out.println("Before swapping: ");
System.out.println("a = " + a);
System.out.println("b = " + b);
int temp = a;
a = b;
b = temp;
System.out.println("After swapping: ");
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
```
Hope that helps! Now for that joke... What did one toilet say to the other toilet? "You look flushed!"
阅读全文