【发布时间】:2015-11-07 18:33:32
【问题描述】:
String input = sc.nextLine();
System.out.println(Boolean.parseBoolean(input));
所以我的输入看起来像 1 > 2 或 false || true,但我没有得到正确的值。
但是当我打电话时:
Boolean x = 1 < 2;
System.out.println(x);
我猜对了。所以我的问题是。 如何将字符串输入转换为返回布尔值?
到目前为止尝试过:
Boolean.parseBoolean();
Boolean.getBoolean();
Boolean.valueOf();
感谢您的回答。
编辑
INPUT - OUTPUT
1 < 2 - false(should be true)
false || true - false(should be true)
【问题讨论】:
-
执行代码时你得到了什么值?请在这里分享。
标签: java boolean user-input