任意运算单元的长度小于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
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...