Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ICSE Java Programming Average Marks 2018 Q9

Thursday, December 29, 2022

ICSE Java Programming Average Marks 2018 Q9

Question 9.
Write a program to accept name and total marks of N number of students in two single subscript array name[] and
totalmarks[ ].  
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.

[deviation = total marks of a student – average] 



import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] name;
        float[] totalmarks;
        int N;
        float averageMarks = 0;
        System.out.println("Enter the number of students:");
        N = in.nextInt();
        in.nextLine();
        name = new String[N];
        totalmarks = new float[N];
        for (int i = 0; i < N; i++) {
            name[i] = "";
            System.out.print("Enter the name of student:");
            name[i] = in.nextLine();
            System.out.print("Enter the total marks of " + name[i] + ":");
            totalmarks[i] = in.nextFloat();
            in.nextLine();
            averageMarks += totalmarks[i];
        }
        System.out.println("The average of the total marks obtained by N Number of students:" + averageMarks / N);
        for (int j = 0; j < N; j++)
            System.out.println("Deviation for " + name[j] + "=" + (totalmarks[j] - (averageMarks / N)));
        in.close();

    }
}

No comments:

Post a Comment