在Java中,我最近刚刚复习了一些方法,我想做一些事情来将我学到的东西应用到实践中。然而,我只是被卡住了。
我在这里尝试做的是打印行“巧克力是什么颜色的? 1.白色2.黑色. 3.棕色.答案是”
从本质上讲,我的目标是让打印行显示“答案是棕色的”。
能给我几句忠告吗?
public static void main(String[] args) {
//What color is chocolate? 1. White 2. Black 3. Brown
int corAns = methodChocolate(3);
if (corAns == 3) {
System.out.println("Brown");
}
System.out.println("What color is chocolate? 1. White 2. Black 3. Brown.
The answer is "+corAns);
}
static int methodChocolate(int ans) {
if (ans == 3) {
return 3;
} else if (ans == 2) {
return 2;
} else if (ans == 1) {
return 1;
}
return 0;
}https://stackoverflow.com/questions/41336646
复制相似问题