Write a Java program to calculate the sum and average of marks of 5 subjects

  • 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;
		
	int sum=marks1+marks2+marks3+marks4+marks5;

	System.out.println("Sum of marks of 5 subjects "+ sum);
		
	int average = sum/5;
	System.out.println("Average marks of 5 subjects "+ average);	
}
}
Output
Sum of marks of 5 subjects 358
        Average marks of 5 subjects 71

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 average i.e. sum divided by number of subjects which is 5 and stored in “sum” and “average” variable of type “int”.
  • 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.