-1

这是显示分数菜单的代码块:

public void scoreBoard() //the score board to keep count; need to display 4 times
{
    Scanner score = new Scanner (System.in);
    for (int k = 1; k <= 4; k++) //repeat for the 4 quarters
    {
      System.out.println( "T : " );
      System.out.println( touchdown * score.nextInt()); //scores of the plays made
      System.out.println("F : ");
      System.out.println(fieldgoal * score.nextInt());
      System.out.println("E : ");
      System.out.println ( extrapnt * score.nextInt());
      System.out.println ("P : ");
      System.out.println ( twopntcon * score.nextInt());
      System.out.println("S : " );
      System.out.println( safety * score.nextInt());
      System.out.println ( "Q : Done with quarter " + k);
    }
}

我似乎无法弄清楚如何使用这些值并计算总分。请帮忙。

4

1 回答 1

1

我假设您的问题是关于如何重用扫描仪值进行计算和打印。尝试这个:

public void scoreBoard() 
{
    int total = 0;
    Scanner score = new Scanner (System.in);
    for (int k = 1; k <= 4; k++) //repeat for the 4 quarters
    {
        int touchdown_score = touchdown * score.nextInt();
        int fieldgoal_score = fieldgoal * score.nextInt();
        int extra_score = extrapnt * score.nextInt();
        int twopnt_score =  twopntcon * score.nextInt();
        int safety_score = safety * score.nextInt();

        System.out.println( "T : " );
        System.out.println( touchdown_score ); //scores of the plays made
        System.out.println("F : ");
        System.out.println(fieldgoal_score);
        System.out.println("E : ");
        System.out.println (extra_score );
        System.out.println ("P : ");
        System.out.println (twopnt_score);
        System.out.println("S : " );
        System.out.println(safety_score);
        System.out.println ( "Q : Done with quarter " + k);
        total+= touchdown_score  + fieldgoal_score + extra_score + twopnt_score + safety_score;
    }
}
于 2013-02-18T20:47:00.300 回答