Knowee
Questions
Features
Study Tools

WAP in Java to accept five subjects marks and calculate the total and average marks.       Example :    Input :     85                            90                           92                           79                           83                   Output : Total Marks : 429  Average Marks : 85.8

Question

WAP in Java to accept five subjects marks and calculate the total and average marks.       Example :    Input :     85                            90                           92                           79                           83                   Output : Total Marks : 429  Average Marks : 85.8

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple Java program that accepts five subject marks, calculates the total and average marks:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] marks = new int[5];
        int total = 0;

        System.out.println("Enter marks for 5 subjects: ");
        for (int i = 0; i < 5; i++) {
            marks[i] = input.nextInt();
            total += marks[i];
        }

        double average = total / 5.0;

        System.out.println("Total Marks: " + total);
        System.out.println("Average Marks: " + average);
    }
}

Here's how this program works:

  1. We first import the Scanner class, which is used to get user input.

  2. We then declare an array of integers to hold the marks for the five subjects.

  3. We also declare a variable to hold the total of the marks.

  4. We then use a for loop to get the marks for each subject from the user. We add each mark to the total.

  5. After we have all the marks, we calculate the average by dividing the total by 5. We use 5.0 instead of 5 to ensure that we get a decimal result.

  6. Finally, we print out the total and average marks.

This problem has been solved

Similar Questions

WAP which accepts marks of four subjects and display total marks, percentage and grade.Hint: more than 70 –> distinction, more than 60 –> first, more than 40 –> pass, less than 40 –> fail

Java Program To Accept the Marks of a Student and Find the Total Marks and Percentage

State and explain four features of java programming language (4 Marks)d) Write a Java program that determines a student’s grade. The program will read three types ofscores(quiz, mid-term, and final scores) and determine the grade based on the following rules: -if theaverage score >=90% =>grade=A -if the average score >= 70% and <90% => grade=B -if theaverage score>=50% and <70% =>grade=C -if the average score<50% =>grade=F(7 Marks)

In an examination the average marks obtained by John in English, Maths, Hindi and Drawing were 50. His average marks in Maths, Science, Social Studies and Craft were 70. If the average marks in all seven subjects is 58, his score in maths was?

If the average marks of two batches of 55 and 45 students respectively is 50 and 60, then the average marks of all the students is:a.54.5b.55c.56.8d.53

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.