【发布时间】:2015-02-19 18:14:23
【问题描述】:
您好,我正在编写具有 5 种操作选择的计算器。
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
我想请用户对操作进行选择,检查选择是否有效(即1-5)如果没有,则给出错误信息并提示用户再次选择。
我正在考虑在 else 语句中使用 if-else 语句和 switch 语句。
System.out.printf("What would you like to do? ");
int selection = input.nextInt();
if (selection!=1 || 2 || 3 || 4 || 5) {
System.out.println("You have entered an invalid choice, please re-enter
your choice: ");
}/*end if as long as the selection is NOT a 1 - 5, prompt the user to
re-enter*/
else {
switch(selection){
case 1:
case 2:
case 3:
case 4:
case 5;
我在 if 行收到 Eclipse 编译器错误:
The operator || is undefined for the argument type(s) boolean, int
任何想法什么是错的以及如何解决这个问题?谢谢
开尔文
【问题讨论】:
标签: java eclipse if-statement switch-statement