KnowledgeBoat Logo

Computer Applications

In an examination, you have appeared for three subjects i.e. Physics, Chemistry and Biology. Write a program in Java to calculate the average mark obtained and finally display the marks in rounded-off form. Take Physics, Chemistry. and Biology marks as inputs.

Java

Java Math Lib Methods

131 Likes

Answer

import java.util.Scanner;

public class KboatAvgMarks
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter Marks");
        System.out.print("Physics: ");
        int p = in.nextInt();
        System.out.print("Chemistry: ");
        int c = in.nextInt();
        System.out.print("Biology: ");
        int b = in.nextInt();
        
        double avg = (p + c + b) / 3.0;
        long roundAvg = Math.round(avg);
        
        System.out.println("Rounded Off Avg Marks = " + roundAvg);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of In an examination, you have appeared for three subjects i.e. Physics, Chemistry and Biology. Write a program in Java to calculate the average mark obtained and finally display the marks in rounded-off form. Take Physics, Chemistry. and Biology marks as inputs.

Answered By

57 Likes


Related Questions