Need help in calculating the average scores of students from 40 exam scores

0 votes
asked Dec 8, 2018 by Lance
retagged Dec 8, 2018
/**

It can't loop for some reason and it doesn't even divided the answer by 40

Help!

*/

import java.util.Scanner;

public class AverageScores{

  public static void main(String [] args){

     Scanner sc = new Scanner(System.in);

double N;

double Sum = 0;

double x = 1;

  

  System.out.println("Input the Exam Result");

      N = sc.nextDouble();

while (x<=40){

    {

           Sum = Sum + N;

   x++;

        }

        }

double average = ++Sum / 40;

        System.out.println("The Average Exam Score of 40 Students is "+average);

  }

}

1 Answer

0 votes
answered Dec 8, 2018 by Adrian

N = sc.nextDouble(); is only executed once, not 40 times as you want. To read 40 numbers move this instruction inside the while() loop.

commented Dec 12, 2018 by Shailesh kumar
N = sc.nextDouble(); is only executed once, not 40 times as you want. To read 40 numbers move this instruction inside the while() loop. and inside the while loop two openings and closing are written instead only one will be there.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...