【发布时间】:2012-02-16 06:36:18
【问题描述】:
基本上,我想做的是根据给定值检查两个整数,因此,通常你会做的是这样的:
//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
}
【问题讨论】:
-
你为什么想要?
-
因为那样代码会更好看?
-
作为一种方法,使包含大量变量检查同一变量的 if 语句变得更加简洁。
-
@grapeot:是一回事;用
0代替x,用a和b代替整数文字。
标签: java