我似乎遇到的问题是,在继续我的程序逻辑之前,我不确定如何让程序识别玩家是否处于“MVP”位置之一(C、SS、CF)。
这三个位置只有当其他人的 OPS 高于 800 时才有资格获得“MVP”资格,而其他人的 OPS 必须达到 900 或以上才能被考虑为“MVP”。 我再一次遇到了“if”和“if else”语句的问题。 再说一遍,这是学校给出的问题,我不想要答案。只有洞察我做错了什么。我想学习这个,但没有人为我做。预先感谢您。
import java.util.Scanner;
public class baseBall {
public static void main(String[] args) {
/* A good part of a baseball player's offensive value is captured by the
statistic OPS - the sum of the player's on base percentage and slugging
percentage. An MVP candidate will typically have an OPS above 900,
however if they play a difficult defensive position (catcher, shortstop, or center field)
then they are an MVP candidate if their OPS is above 800. Write a program that will prompt the user for
a player's name, their on base percentage, slugging percentage, and defensive position and report whether the player is an MVP candidate*/
Scanner input = new Scanner(System.in);
System.out.println("Please enter players name: ");
String name = input.next();
System.out.println("Please enter On Base Percentage: ");
double Obp = input.nextDouble();
System.out.println("Please enter slugging Percentage: ");
double Slg = input.nextDouble();
System.out
.println("Please enter position (P,C,1B,2B,3B,SS,LF,CF,RF): ");
String ball = input.next();
String position;
double Ops = Obp + Slg;
if ( position.equalsIgnoreCase("ss")){
if (position.equalsIgnoreCase("cf")){
if (position.equalsIgnoreCase("c")){
System.out.println("MVP Candidate!");
else
System.out.println("NOT an MVP Candidate!);
}
}
}
}
}
最佳答案
尝试在没有嵌套 IF 的情况下执行此操作。相反,请尝试使用 boolean 运算符,例如 AND 和 OR。
如前所述,首先尝试使用纸张。尝试绘制决策树,看看可能出了什么问题以及出在哪里。
关于java - 如果和如果再一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33333290/