用java写一个和上面不同的程序,实现输入值的交换
时间: 2024-04-30 18:22:37 浏览: 42
当然可以!下面是一份 Java 代码:
```
import java.util.Scanner;
public class SwapValues {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一个数:");
int num1 = input.nextInt();
System.out.print("请输入第二个数:");
int num2 = input.nextInt();
System.out.println("交换前:num1 = " + num1 + ", num2 = " + num2);
int temp = num1;
num1 = num2;
num2 = temp;
System.out.println("交换后:num1 = " + num1 + ", num2 = " + num2);
}
}
```
希望这能解决您的问题!现在,请问您有什么其他问题吗?
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)