I want to find out the greatest number, out of three given numbers, using switch-case(without using if) I answered the question using this program, which works:
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;
}
}
Does anyone have any simpler answer?
It's kinda stupid, but here you go.
switch(1)
{
default:
return Math.max(a, Math.max(b, c));
}