java - 如果和如果再一次

标签 java if-statement

我似乎遇到的问题是,在继续我的程序逻辑之前,我不确定如何让程序识别玩家是否处于“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/

相关文章:

java - jython 中的 SSL 非法状态异常

java - 错误: incompatible types: MainFragment cannot be converted to Activity

for-loop - 我的逻辑哪里错了?

regex - IF 语句在 RHEL 6 中不起作用(在 RHEL 5 中起作用)

javascript - 如何在javascript中的if中将OR切换为AND

java - 如何使用在 java 中的其他方法中返回的数组?

java - 理解GridView的Java语法 gridview = (GridView) findViewById(R.id.gridview);

java - 使用@Immutable注解不可变的Java类有什么好处?

c# - 具有 2 个操作的单行 if 语句

python - 我对这段代码的分析是否正确,为什么会这样写?