一道关于boolean的题目

xxm712 2008-12-14 12:52:34

public static void main(String[] args) {

int i = 0;
boolean b = true;
b = i < 10 | true; //这里怎么个运算法啊 boolean 转换成进制怎么分配位数的 全一(全零)还是只占一位
System.out.println(b);

}

提示的那句的运行过程是怎么样的 请详细说下 谢谢
...全文
84 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZangXT 2008-12-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fox000002 的回复:]
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, butits "size" isn't something that's precisely defined.

boolean 所占的位数没有明确规定

如果占 1 byte 的话,那么一般各位置上填充相同的值
[/Quote]
jvm规范里还是有相关规定的。
fox000002 2008-12-14
  • 打赏
  • 举报
回复
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

boolean 所占的位数没有明确规定

如果占 1 byte 的话,那么一般各位置上填充相同的值
ZangXT 2008-12-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xxm712 的回复:]
boolean 不是占一个字节么  到底怎么分配的 就是最后一位决定么
[/Quote]
不要考虑boolean占多大的问题,只要明确|在这里是逻辑或就可以了,|和||就是非短路计算和短路计算的区别。
关于boolean类型,一般的java书上都会说它占用一个bit,而实际的jvm会用一个int表示1个boolean变量,而用byte数组表示boolean数组。
xxm712 2008-12-14
  • 打赏
  • 举报
回复
boolean 不是占一个字节么 到底怎么分配的 就是最后一位决定么
RJCHEN1985 2008-12-14
  • 打赏
  • 举报
回复
| 是非短路的逻辑或运算符,不像||,即使第一个表达式判断为true,|也会计算第二个表达式
liao82 2008-12-14
  • 打赏
  • 举报
回复
i<10 =false
false | true = true

boolen 就是0或1

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧