Is there a simpler way to check multiple values against one value in an if-statement?

前端 未结 12 869
名媛妹妹
名媛妹妹 2020-11-27 07:55

Basically, what I want to do is check two integers against a given value, therefore, classically what you would do is something like this:

//just to get some         


        
12条回答
  •  攒了一身酷
    2020-11-27 08:18

    if(a == 0 || b == 0)
    {
    //Then do something
    }
    

    Why not keep it readable? What is not concise about this? On the other hand,

    a = (int)(Math.random()*5);
    

    involves an unnecessary cast. Why not just use Random and invoke nextInt()?

提交回复
热议问题