Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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,我在做这部分的时候需要帮助 “确定有多少分数高于或等于平均值,有多少分数低于平均值。” 有人能给出一些如何获得所需输出的想法吗 例如:输入要处理的测验分数:5 比分1:10 比分2:8 比分3:9 比分4:2 比分5:4 结果 ======= 平均值为6.6 高于或等于平均分的分数为3 低于平均分的分数为2 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Syst

我在做这部分的时候需要帮助

“确定有多少分数高于或等于平均值,有多少分数低于平均值。”

有人能给出一些如何获得所需输出的想法吗

例如:输入要处理的测验分数:5

比分1:10

比分2:8

比分3:9

比分4:2

比分5:4

结果

=======

平均值为6.6

高于或等于平均分的分数为3

低于平均分的分数为2

public static void main(String[] args) {

  Scanner scanner = new Scanner(System.in);
  
  System.out.print("Enter number of quiz scores to process:");
  int totalScore=scanner.nextInt();

  int[]scoreNum= new int[totalScore];
  
  int i; 
  double total=0.0;
    
  for(i=0;i<totalScore;i++){
  System.out.printf("Score %d:", i+1 );
  scoreNum[i]=scanner.nextInt();
  total += scoreNum[i];
  }
  
  double average=total/totalScore;
  System.out.format("The Average is :%.1f\n",average); 
       
publicstaticvoidmain(字符串[]args){
扫描仪=新的扫描仪(System.in);
System.out.print(“输入要处理的测验分数:”);
int totalScore=scanner.nextInt();
int[]scoreNum=新的int[totalScore];
int i;
双倍合计=0.0;
对于(i=0;i请尝试以下代码:

Scanner scanner = new Scanner(System.in);

    System.out.print("Enter number of quiz scores to process:");
    int totalScore = scanner.nextInt();
    float[] scores = new float[totalScore];
    float total = 0;

    for (int i = 0; i < totalScore; i++) {
        System.out.print("Score " + (i + 1) + ": \n");
        scores[i] = scanner.nextFloat();
        total += scores[i];
    }

    float average = total / totalScore;
    int scoresAbove = 0;
    int scoresBelow = 0;

    for (int a = 0; a < scores.length; a++) {
        if (scores[a] >= average) {
            scoresAbove++;
        } else {
            scoresBelow++;
        }
    }

    System.out.println("The average is: " + average + "\n Number of scores above or equal to the average is " + scoresAbove + "\n Number of scores below the average is " + scoresBelow);
Scanner Scanner=新的扫描仪(System.in);
System.out.print(“输入要处理的测验分数:”);
int totalScore=scanner.nextInt();
浮动[]分数=新浮动[总分数];
浮动总数=0;
对于(int i=0;i=平均值){
scoresAbove++;
}否则{
分数低于++;
}
}
System.out.println(“平均值为:“+average+”\n高于或等于平均值的分数为“+scoresAbove+”\n低于平均值的分数为“+scoresBelow”);

您的变量在for循环之前声明,因此在for循环之后也可以使用它们(在您当前打印平均值的位置)。在计算平均值之后,您可能需要另一个循环来再次检查分数值:cc@JuhaLahio

public static void main(String[] args) {

  Scanner scanner = new Scanner(System.in);
  
  System.out.print("Enter number of quiz scores to process:");
  int totalScore=scanner.nextInt();

  int[]scoreNum= new int[totalScore];
  
  int i; 
  double total=0.0;
    
  for(i=0;i<totalScore;i++){
  System.out.printf("Score %d:", i+1 );
  scoreNum[i]=scanner.nextInt();
  total += scoreNum[i];
  }
  
  double average=total/totalScore;
  System.out.format("The Average is :%.1f\n",average); 

  int countLesser = 0;
  int countGreater = 0;
  for (int i = 0; i < totalScore; i++) {
    if(scoreNum[i] > average) countGreater++;
    else if(scoreNum[i] < average) countLesser++;
  }
  System.out.println("Greater: " + countGreater + " Lesser: " + countGreater);

  }
publicstaticvoidmain(字符串[]args){
扫描仪=新的扫描仪(System.in);
System.out.print(“输入要处理的测验分数:”);
int totalScore=scanner.nextInt();
int[]scoreNum=新的int[totalScore];
int i;
双倍合计=0.0;
对于(i=0;i平均值)countmorer++;
else if(scoreNum[i]
欢迎来到Stack Overflow。请学习Stack Overflow的工作原理,并阅读如何提高问题的质量。然后检查,看看您可以问什么问题。请参阅:。您遇到的确切问题是什么?您使用一个简单的
if()
运算符来查看一个值是小于还是大于另一个值。看起来您只发布了一半的代码或是学校作业。总之,在解决方案中,我看到您已经有了平均值。现在您已经有了平均值和输入的数字,只需在该数组上循环
scoreNum
,然后进行比较它与
average
。谢谢你的建议,我认为我面临的问题就是让用户输入有点if(),因为用户输入是循环的一部分,平均声明和计算发生在循环之后,所以我面临一个问题,我无法让用户输入成为if()的一部分变量在for循环之前声明,因此在for循环之后也可用(在您当前打印平均值的位置。在计算平均值后,您可能需要另一个循环来再次检查分数值。@SooKinChun看一看我的答案谢谢,我使用您的代码并尝试使用方法other comment for me,其中使用array scoreNum并将其与total/totalScore进行比较。我得到了这些错误。)或者线程“main”java.lang.ArrayIndexOutofBounds异常:Practical3Q1StackoverFlow.main中的5(Practical3Q1StackoverFlow.java:25)可能您将分数写在分数显示的同一行中,您必须将其写在分数n的行下