Write a Java program to calculate the percentage of 5 subject marks

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

Solution

import java.util.Scanner;
public class ClassName {
public static void main(String[] args) {
int marks1=69;
int marks2=76;
	int marks3=85;
	int marks4=50;
	int marks5=78;
		
	double sum = marks1+marks2+marks3+marks4+marks5;
	double total = 500;
		
	double percentage = sum/total*100;

System.out.println("Percentage of marks of 5 subjects  "+ percentage);
}
}
Output
Percentage of marks of 5 subjects 71.6

Explanation

  • Five Variables are declared to store marks of 5 subjects of data type “int”.
  • Calculate sum i.e. addition of marks using the “+” operator.
  • And percentage i.e. sum divided by total marks which is 500 and multiplied by 100.
  • Store the result in the “sum” and “percentage” variables of type “double”. Because percentage resulted in decimal.
  • Print the result using System.out.println() statement.
QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.