0

I am working on a project which involves entering multiple peoples name and mark which then works out the average and outputs the name and mark of people above the average.

public static void main(String[] args) {
    Scanner kybd = new Scanner(System.in);

    int sum = 0;
    double average = 0;

    System.out.println("Enter How many students");

    int numberOfStudents = kybd.nextInt();

    if (numberOfStudents <= 0) {
        System.out.println("No Students");
    }

    if (numberOfStudents > 0) {

        String[] studentNames = new String[numberOfStudents];
        int[] marks = new int[numberOfStudents];

        for (int i = 0; i < numberOfStudents; i++) {

            System.out.println("Please Enter Name");
            studentNames[i] = kybd.nextLine();

            kybd.next();

            System.out.println("Please Enter Marks");
            marks[i] = kybd.nextInt();

            sum += marks[i];
            average = (double) sum / numberOfStudents;
        }
        System.out.println("average" + average);

        System.out.print("Scores Above the Average: ");

        for (int i = 0; i < numberOfStudents; i++) {
            if (marks[i] > average) {
                System.out.print(marks[i] + ", " + studentNames[i] + ", ");

            } else {
            }
        }
    }
}

The problem i am getting is that the marks above the average output but the names don't

M Daley
  • 15
  • 3

0 Answers0