当前位置:网站首页>Exclusive or operator simple logic operation a^=b
Exclusive or operator simple logic operation a^=b
2022-06-25 23:02:00 【if you never leave me, i will be with you till death do us apart】
^ Is a bitwise XOR operation
a^=b Equivalent to a = ab, among It's a bitwise exclusive or operation , the a And b XOR operation on the corresponding bit of , A fellow 0 Or both 1 when , The corresponding bit result is 0; Otherwise 1.
hypothesis ,a The value of is binary 1010,b The value of is binary 1100, that a^b = 0110
describe
Enter two positive integers a and b, Output the sum of these two positive integers , Bad , product , merchant , model ( if a>b The output a-b,a/b,a%b The value of... Is output in reverse b-a,b/a,b%a Value , Do not consider decimals , Please use int type )
Input description :
Two positive integers
Output description :
Their and , Bad , product , merchant , model . Each value is separated by a space
Example 1
public static void main(String[] args) {
System.out.println(" Please enter two decimal places ");
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
scanner.close();
// The above code Basic is the basic data input
// Here's your judgment Default to a>b When By default, the data of the following program will be used ( skip if) In line with business logic
// When he was less than b Enter the following if
//EG:a=10 2 Of 3 Power +2 Of 1 The second party is =10 So his value is 1010
// b=20 2 The fourth power of +2 To the power of = 10100
if (a < b) {
//a=a^b a= 1010^10100= 1110 =30
a ^= b;
//b= b^a; a=30 b=20 20^30=10 b=10
b ^= a;
//a=a^b a=30 b=10 a=20 b=10 Equivalent position It is equivalent to changing the value position
a ^= b;
}
// %d: Integer output Convert the contents of his output to the shape output
System.out.printf("%d %d %d %d %d", a + b, a - b, a * b, a / b, a % b);
}
The result of his output is :
Please enter two decimal places
10
20
30 10 200 2 0
Another relatively simple method of operation :
if(a>b){
System.out.println((a+b)+" "+(a-b)+" "+(a*b)+" "+(a/b)+" "+(a%b));
}else{
System.out.println((a+b)+" "+(b-a)+" "+(a*b)+" "+(b/a)+" "+(b%a));
}
}
边栏推荐
- Flutter 網絡請求封裝之Dio(Cookie管理、添加攔截器、下載文件、异常處理、取消請求等)
- adb常用命令
- 一位博士在华为的22年
- Unity技术手册 - 生命周期旋转RotationOverLifetime-速度旋转RotationBySpeed-及外力
- C language and the creation and use of database
- 简单好用的缓存库 gcache
- How do I project points on a 3D plane- How to project a point onto a plane in 3D?
- 民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
- Programmer weekly (issue 4): the wealth view of programmers
- 华为云短信测了很多手机都提示发送频繁
猜你喜欢

2022-2028 global SiC igniter industry research and trend analysis report

Nacos 源码分析01 代码结构

oracle -- 表操作

Talk about adapter mode

如何用jmeter做接口测试
[invitation letter] on March 4, the platform enabled digital intelligence Innovation -- UFIDA BiP PAAS cloud platform IUAP digital intelligence hundred cities forum · Jinan Station
This 110 year old "longevity" enterprise has been planning for the next century

Eureka core ⼼ source code analysis

2022-2028 global horizontal reciprocating compressor industry research and trend analysis report

民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
随机推荐
2022-2028 global extrusion coating and lamination production line industry research and trend analysis report
Chapter 3 use of requests Library
Why can't the mobile phone be used and the computer be connected
The new version of Tencent's "peace elite" is coming: add a new account security protection system, and upgrade the detection of in-game violations
Programmer weekly (issue 4): the wealth view of programmers
你好,请问老师,在支付宝基金开户真的安全吗?
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
2022-2028 global cloud based remote browser isolation industry research and trend analysis report
ES6 --- 数值扩展、对象拓展
2022-2028 global variable frequency compressor technology industry research and trend analysis report
How to disable the optical drive
Unity技术手册 - 生命周期旋转RotationOverLifetime-速度旋转RotationBySpeed-及外力
Yyds dry goods inventory JD 2, why is redis so fast?
2022-2028 global horizontal reciprocating compressor industry research and trend analysis report
Talk about adapter mode
2022-2028 global industrial touch screen industry research and trend analysis report
Flutter 网络请求封装之Dio(Cookie管理、添加拦截器、下载文件、异常处理、取消请求等)
adb常用命令
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028