Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在正确的位置放置支架时有问题吗?_Java - Fatal编程技术网

Java 在正确的位置放置支架时有问题吗?

Java 在正确的位置放置支架时有问题吗?,java,Java,我对编程有点陌生,我一直努力想弄清楚的问题是。我的控制台应用程序询问用户想要输入多少测试分数来计算所有分数的平均值和总和。如果他们输入3,则要求他们输入3个测试分数,然后显示所有分数的平均值和总和。然后询问他们是想继续还是结束该计划,如果他们输入yes continue,则应重新开始。我的问题是,当我说“是”时,它没有清除总数或分数计数,它只是从上一个继续,只是将新的分数添加到其中 import java.util.Scanner; public class TestScoreApp {

我对编程有点陌生,我一直努力想弄清楚的问题是。我的控制台应用程序询问用户想要输入多少测试分数来计算所有分数的平均值和总和。如果他们输入3,则要求他们输入3个测试分数,然后显示所有分数的平均值和总和。然后询问他们是想继续还是结束该计划,如果他们输入yes continue,则应重新开始。我的问题是,当我说“是”时,它没有清除总数或分数计数,它只是从上一个继续,只是将新的分数添加到其中

 import java.util.Scanner;

 public class TestScoreApp
 {
       public static void main(String[] args)
       {
           // display operational messages
           System.out.println("Please enter test scores that range from 0 to 100.");
           System.out.println("To end the program enter 999.");
           System.out.println();  // print a blank line

           // initialize variables and create a Scanner object
           int scoreTotal = 0;
           int scoreCount = 0;
           int testScore = 0;
           Scanner sc = new Scanner(System.in);
           String choice = "y";

           // get a series of test scores from the user
           while (!choice.equalsIgnoreCase("n"))
           {
               System.out.println("Enter the number of test score to be entered: ");
               int numberOfTestScores = sc.nextInt();

               for (int i = 1; i <= numberOfTestScores; i++)
               {
                    // get the input from the user
                    System.out.print("Enter score " + i + ": ");
                    testScore = sc.nextInt();

                    // accumulate score count and score total
                    if (testScore <= 100)
                    {
                         scoreCount = scoreCount + 1;
                         scoreTotal = scoreTotal + testScore;
                    }
                    else if (testScore != 999)
                          System.out.println("Invalid entry, not counted");


                }
                double averageScore = scoreTotal / scoreCount;
                String message = "\n" +
                     "Score count:   " + scoreCount + "\n"
                   + "Score total:   " + scoreTotal + "\n"
                   + "Average score: " + averageScore + "\n";
                System.out.println(message);
                System.out.println();
                System.out.println("Enter more test scores? (y/n)");
                choice= sc.next();
          }



    // display the score count, score total, and average score



    }
}
import java.util.Scanner;
公共类TestScoreApp
{
公共静态void main(字符串[]args)
{
//显示操作信息
System.out.println(“请输入从0到100的测试分数”);
System.out.println(“要结束程序,请输入999”);
System.out.println();//打印一个空行
//初始化变量并创建扫描程序对象
int scoreTotal=0;
积分计数=0;
int testScore=0;
扫描仪sc=新的扫描仪(System.in);
字符串选择=“y”;
//从用户处获取一系列测试分数
而(!choice.equalsIgnoreCase(“n”))
{
System.out.println(“输入要输入的测试分数:”);
int numberOfTestScores=sc.nextInt();

对于(int i=1;i只需在while循环开始后移动分数变量声明:

// create a Scanner object
Scanner sc = new Scanner(System.in);
String choice = "y";

// get a series of test scores from the user
while (!choice.equalsIgnoreCase("n"))
{
    // initialize variables
    int scoreTotal = 0;
    int scoreCount = 0;
    int testScore = 0;

    System.out.println("Enter the number of test score to be entered: ");
    int numberOfTestScores = sc.nextInt();

这样,每次进程再次启动时,它们都将在0处初始化。

while循环中的第一条语句应将scoreTotal和scoreCount设置为0。

感谢您的帮助