Java テストの質問

if() ステートメントには括弧内の比較式が含まれており、戻り値は true または false です。if(x=y) は y を x に代入しますが、データ型が int であるため、コンパイルは通過できません。

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("相等");
     }
}

おすすめ

転載: blog.csdn.net/weixin_42797483/article/details/132524613