我正在学习入门级 Java 类(class),我们的第一份作业让我难住了,主要是因为要求使它变得非常不方便。
The output y shall be equal to two times the value of the input x if such input is an integer number between 0 and 4, inclusive.
The output y shall be equal to the value of the input x if such input is an integer number between 5 and 9, inclusive.
The output y shall be equal to 0 if the input x is an integer number between 10 and 14, inclusive.
The code MUST NOT make use of "if" statements, "switch-case" statements, "for" loops, "while" loops, Boolean variables, or Boolean expressions
如果不实际使用条件语句,我该如何做到这一点?
最佳答案
您可以使用一个简单的数学方程:
int y = x * (2 - (x / 5));
关于java - 没有实际使用任何条件语句的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46309804/