方法一:使用第三个变量进行值互换
```java
int a = 5;
int b = 10;
int temp;
System.out.println("Before swapping: a = " + a + ", b = " + b);
temp = a;
a = b;
b = temp;
System.out.println("After swapping: a = " + a + ", b = " + b);
```
方法二:通过数学运算进行值互换
```java
int a = 5;
int b = 10;
System.out.println("Before swapping: a = " + a + ", b = " + b);
a = a + b;
b = a - b;
a = a - b;
System.out.println("After swapping: a = " + a + ", b = " + b);
```
上述两种方法都可以实现两个变量的值互换,你可以根据自己的喜好选择其中一种方法。