代碼返回值的為什么不是布爾型
public class HelloWorld{
??? public static void main(String[] args) {
?? ??? ?int a=16;
?? ??? ?double b=9.5;
?? ??? ?String str1="hello";
?? ??? ?String str2="imooc";
?? ??? ?System.out.println("a等于b:" + (a==b));
?? ??? ?System.out.println("a大于b:" + (a>b));
?? ??? ?System.out.println("a小于等于b:" + (a<=b));
?? ??? ?System.out.println("str1等于str2:" +(str1 =str2));
?? ?}
}
輸出值
<pre>a等于b:false a大于b:true a小于等于b:false str1等于str2:imooc
2017-09-13
true 和 false 就是布爾型, 你問的是“str1等于str2”返回值是 “imooc”而不是“false”是因?yàn)槟阌玫馁x值符號(hào)=而不是判斷符號(hào)==。希望有用。