False boolean = True?

前端 未结 7 1019
粉色の甜心
粉色の甜心 2020-12-07 02:12

I found this code in a book and I executed it in Netbeans:

boolean b = false;
if(b = true) {
    System.out.println(\"true\");
} else {
    System.out.printl         


        
相关标签:
7条回答
  • 2020-12-07 03:08

    In your "if" statement you are assigning the value "true" to b. You should check the value by using the comparison operator "==".

    boolean b = false;
    
    if(b == true)
    {
       System.out.println("true");
    }
    else
    {
       System.out.println("false");
    }
    
    0 讨论(0)
提交回复
热议问题