不使用第三方变量交换值

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/qq_42920045/article/details/84656534

原作者地址: https://yq.aliyun.com/articles/674152

public static void main(String[] args) {
	
    int i = 1;
    int j = 2;

    i = i + j;// i = 3 : j = 2

    j = i - j;// j = 1 : i = 3

    i = i - j;// i = 2 : j = 1

    System.out.println("i:" + i + ", j:" + j);

}

执行结果

i:2 , j:1

猜你喜欢

转载自blog.csdn.net/qq_42920045/article/details/84656534