首先,问题是"编写一个Java程序,使用三元运算符找到三个最小的数字."
这是我的代码:
class questionNine
{
public static void main(String args[])
{
int x = 1, y = 2, z = 3;
int smallestNum;
smallestNum = (x<y && x<z) ? x : (y<x && y<z) ? y : (z<y && z<x) ? z;
System.out.println(smallestNum + " is the smallest of the three numbers.");
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在三元运算符中使用多个条件,但这不起作用.几天我不在,所以我不确定该做什么,老师的电话已关闭.有帮助吗?