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)
執行代碼時你獲得了什麼值?請在此分享。 –