我想使用 switch-case 找出三个给定数字中的最大数字(不使用 if) 我使用这个程序回答了这个问题,它有效:
class GreatestNoSwitch{
public int main(int a, int b, int c){
int d = (int)Math.floor(a/b);
int max = 0;
switch(d){
case 0:
max = b;
break;
default:
max = a;
}
d = (int)Math.floor(max/c);
switch(d){
case 0:
max = c;
}
return max;
}
}
有人有更简单的答案吗?
最佳答案
这有点愚蠢,但你就可以了。
switch(1)
{
default:
return Math.max(a, Math.max(b, c));
}
关于java - 使用 switch case 的三个数字中最大的一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11484132/