解决java数据交换之谜
Java  /  管理员 发布于 2年前   142
交换两个数字的方法有以下三种 ,其中第一种最常用
/*输出最小的一个数*/public class jiaohuan1 {public static void main(String[] args) {int a =4;int b = 3;if(a<b){ // 第一种交换方式int tmep = a;a = b;b = tmep; }System.out.println(a);}}/* 运行结果; 3*/
第二种方法
/*输出最小的一个数*/public class jiaohuan1 {public static void main(String[] args) {int a =4;int b = 3;if(a<b){ a = a + b; b = a - b;a = a - b; }System.out.println(a);}}/* 运行结果; 3*/
第三种方法
/*输出最小的一个数*/public class jiaohuan1 {public static void main(String[] args) {int a =4;int b = 3;if(a<b){ //使用异或来交换大小 ,先将数字转换成二进制的 ,异或是相同的为0,不同的为1 a = a^b; //a = 00000111 7 b = a^b; //b = 00000011 3 a = a^b; //a = 00000100 4// b = 3 00000011// a = 4 00000100// a+b=7 00000111 }System.out.println(a);}}/* 运行结果; 3*/
nkt 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 用了三分钟就被禁了,直接阿里云服务器22端口都禁了..熊丽 在
安装docker + locust + boomer压测环境实现对接口的压测中评论 试试水..博主 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 @test 也可能是国内大环境所至,也是好事,督促你该研究学习新技术..test 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 打了一次网页,然后再也打不开了。。是阿里云的缘故吗?..博主 在
centos7中Meili Search搜索引擎安装流程步骤中评论 @鹿 执行以下命令看看你的2.27版本是否存在strin..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号