给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。
public int aplusb(int a, int b) {
// write your code here
if((a&b)==0){
return a^b;
}else{
return aplusb(a^b,(a&b)<<1);
}
}
本文介绍了一种特殊的方法来实现两个整数的相加操作,该方法避免了使用传统的加法运算符,而是通过位操作来完成加法计算。
给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。
public int aplusb(int a, int b) {
// write your code here
if((a&b)==0){
return a^b;
}else{
return aplusb(a^b,(a&b)<<1);
}
}
863
372

被折叠的 条评论
为什么被折叠?