热门
join now

【NB】任意运算单元的长度小于int顶折

编程相关3周前更新 云程
30 0 0

任意运算单元的长度小于int顶折
如果任何运算单元的长度都不超过int。
那么运算结果就按照int来计算
byte a = 1;
byte b= 2;
a+b -> int 类型

public class HelloWorld {
public static void main(String[] args) {
byte a = 1;
byte b= 2;
byte c = (byte) (a+b); //虽然a b都是byte类型,但是运算结果是int类型,需要进行强制转换
int d = a+b;
}
}

%取模顶折
% 取余数,又叫取模
5除以2,余1

public class HelloWorld {
public static void main(String[] args) {

int i = 5;
int j = 2;
System.out.println(i%j); //输出为1
}
}

【NB】任意运算单元的长度小于int顶折

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...