【发布时间】:2016-03-26 19:49:53
【问题描述】:
这是我的任务,我正在尝试仅使用简短的 if 语句来执行此操作,我得到的唯一错误是使用 "(0.5",除此之外,施工对吗?
Scanner scn = new Scanner(System.in);
int years,kg,cm,MenuA,MenuB,MenuC,A,B,C;
String not;
double ratio = cm/kg;
System.out.println("Please enter your age (years), weight(kg) and height(cm) in that order with spaces");
years = scn.nextInt();
kg = scn.nextInt();
cm = scn.nextInt();
MenuA = (20<years<<11||40<<years<21)&&(0.5<=ratio<2)?A:MenuB;
MenuB = (20<years<<11)&&(2<=ratio<<3.5)?B:MenuC;
MenuC = (40<<years<21)&&(2<=ratio<<3.5)?C:not;
}
}
【问题讨论】:
-
你为什么要移位?您已经完成了“20
-
你也不能写
0.5<=ratio<2。它只是 Java 不支持的语法。 -
我认为您误解了您可以使用类似于
5 < x < 7的表达式来表示“x 介于 5 和 7 之间”。这在 Java 中不存在。而<<确实是移位操作,不是比较操作。
标签: java eclipse if-statement operators short