当前位置:网站首页>异或运算符简单逻辑运算 a^=b
异或运算符简单逻辑运算 a^=b
2022-06-25 21:50:00 【你若不离不弃,我必生死相依】
^为按位异或运算
a^=b等价于a = ab,其中是位异或运算,即将a与b的对应位进行异或运算,同为0或者同为1时,对应位结果为0;否则为1。
假设,a的值为二进制的1010,b的值为二进制的1100,那么a^b = 0110
描述
输入两个正整数a和b,输出这两个正整数的和,差,积,商,模(若a>b则输出a-b,a/b,a%b的值反之输出b-a,b/a,b%a的值,不考虑小数,请使用int类型)
输入描述:
两个正整数
输出描述:
它们的和,差,积,商,模。每个值之间用空格隔开
示例1
public static void main(String[] args) {
System.out.println("请输入两位小数");
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
scanner.close();
//上面的代码 基本就是输入的基本数据
//下面你的判断 先默认 a>b的时候 默认走下面程序的数据(跳过if) 符合业务逻辑
//当他在小于b的进入下面的if
//EG:a=10 2的3次方+2的1次方为=10 那么他的值为 1010
// b=20 2的四次方+2的次方 = 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 相当把位置 相当于把值位置调换
a ^= b;
}
// %d:整型输出 转换他的输出的内容为整形输出
System.out.printf("%d %d %d %d %d", a + b, a - b, a * b, a / b, a % b);
}
他的输出的结果是:
请输入两位小数
10
20
30 10 200 2 0
另一种比较简单运算方式:
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));
}
}
边栏推荐
- Nacos source code analysis 01 code structure
- Youku IPv6 evolution and Practice Guide
- App test points
- Flutter 網絡請求封裝之Dio(Cookie管理、添加攔截器、下載文件、异常處理、取消請求等)
- Data annotation in the second half: growth flywheel under PLG mode Manfu Technology
- Unity技术手册 - 生命周期旋转RotationOverLifetime-速度旋转RotationBySpeed-及外力
- A3.ansible production practice case -- system initialization roles
- Use apiccloud AVM multi terminal component to quickly realize the search function in the app
- APP测试要点
- Talk about adapter mode
猜你喜欢

Canoe: the fifth simulation project: simulation + test

ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?

聊聊Adapter模式

Fujilai pharmaceutical has passed the registration: the annual revenue is nearly 500million yuan. Xiangyun once illegally traded foreign exchange

What is 5g? What can 5g do? What will 5g bring in the future?

Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland

简单好用的缓存库 gcache

Talk about adapter mode
To ensure the Beijing Winter Olympic Games, digital data gives a power without code!
随机推荐
Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland
How to design a complex business system? From the understanding of domain design, cloud native, micro service, and middle platform
Analysis of gpl3.0 license software copyright dispute cases
ES7/ES9 -- 新特性与正则
Hello, teacher, is it really safe to open an account in Alipay fund?
The difference between synchronize and volatile
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
聊聊Adapter模式
Exclusive interview with deepmindceo hassabis: we will see a new scientific Renaissance! AI's new achievements in nuclear fusion are officially announced today
Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?
[invitation letter] on March 4, the platform enabled digital intelligence Innovation -- UFIDA BiP PAAS cloud platform IUAP digital intelligence hundred cities forum · Jinan Station
Jz-064- maximum value of sliding window
Application runtime layotto enters CNCF cloud native panorama
Analysis of China's tractor manufacturing and operation situation and forecast report of prospect trend 2022-2028
华为云短信测了很多手机都提示发送频繁
A3.ansible production practice case -- system initialization roles
APP-新功能上线
2022爱分析· IT运维厂商全景报告
OSPF - detailed explanation of GRE tunnel (including configuration command)
2022-2028 global vacuum jacket system industry survey and trend analysis report