基本上,我想要做的是根据给定值检查两个整数,因此,通常您会做这样的事情:
//just to get some values to check
int a, b;
a = (int)(Math.random()*5);
b = (int)(Math.random()*5);
//the actual thing in question
if(a == 0 || b == 0)
{
//Then do something
}
但是有没有更简洁的格式来做到这一点?可能类似于此(返回错误的操作数类型):
//just to get some values to check
int a, b;
a = (int)(Math.random()*5);
b = (int)(Math.random()*5);
//the actual thing in question
if((a||b) == 0)
{
//Then do something
}
最佳答案
您可以在纯java中执行以下操作
Arrays.asList(a, b, c, d).contains(x);
关于java - 是否有一种更简单的方法来检查 if 语句中的多个值与一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26081060/