java test questions

The if() statement contains a comparison expression in parentheses, and the return value is either true or false. if(x=y) assigns y to x, but the data type is int, so compilation cannot pass.

public class IfTest{
    
    
    public static void main(String[] args){
    
    
        int x=3;
        int y=1;
        if(x=y)
            System.out.println("不相等");
        else
            System.out.println("相等");
     }
}

Guess you like

Origin blog.csdn.net/weixin_42797483/article/details/132524613