Dremendo Tag Line

Calculate total marks and percentage in Java

Input - Question 18

In this question, we will see how to input marks obtained in 5 different subjects in Java programming using the java input and find out the total marks and percentage obtained. To know more about java input click on the java input lesson.

Q18) Write a program in Java to input marks obtained in 5 different subjects and find out the total marks and percentage obtained by the student. Assume that the maximum mark in each subject is 100.

Program

import java.util.Scanner;

public class Q18
{
    public static void main(String args[])
    {
        int e,m,h,g,c,total;
        float per;
        Scanner sc=new Scanner(System.in);
        System.out.print("English ");
        e=sc.nextInt();
        System.out.print("Maths ");
        m=sc.nextInt();
        System.out.print("History ");
        h=sc.nextInt();
        System.out.print("Geography ");
        g=sc.nextInt();
        System.out.print("Computer ");
        c=sc.nextInt();
        total=e+m+h+g+c;
        per=(total/500.0f)*100;
        System.out.println("Total Marks=" + total);
        System.out.print("Percentage=" + per);
    }
}

Output

English 75
Maths 62
History 84
Geography 77
Computer 91
Total Marks=389
Percentage=77.8
video-poster