In this tutorial you will learn about the Java Program to calculate Marks Average and its application with practical example.
Java Program to calculate Marks Average
In this tutorial, we will learn to create a Java program that will calculate Marks Average using Java programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:
- Operators in Java Programming.
- Basic Input and Output function in Java Programming.
- Basic Java programming.
- Arithmetic operations in Java Programming.
What is a percentage of numbers?
The percentage of all the marks is calculated by adding the total marks. And then we will divide it by the maximum marks and multiplied by 100.
What is the average of numbers?
The average of numbers in mathematics means that all the numbers are added and then the sum of all the numbers is divided by the total number of objects.
It means if there are 5 subject marks as follows {60,60,60,80,70} then the average will be:-
average = 60+60+60+80+70/5
average = 60.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
1. Declaring the variables for the program. 2. Taking the input marks from the user. 3. Adding those marks finding the total. 4. Finding the average from the total marks. 5. Finding the percentage of those marks. 5. Printing the result numbers. 7. End Program. |
Program to calculate Average of marks.
In this program, we will first take the marks of all five subjects from the user. And then we will add them to find the total marks. Now the total will be divided by the number of subjects to find the average. Then the total will divide by maximum marks by 5. Last, we will print the output average marks.
Example using the below program.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import java.util.*;//Importing the package. class AvgMarks { //Body of the main function public static void main(String args[]) { //Declaring the required variable for the program. int i; //Taking the input number of subjects from the user. System.out.println("Enter number of subjects"); //Scanning the input from the user Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n]; double avg=0; //Taking the marks from the user for the subjects System.out.println("Enter marks"); for( i=0;i<n;i++) { a[i]=sc.nextInt(); } for( i=0;i<n;i++) { avg=avg+a[i]; } //calculating the average of the marks System.out.print("Average of ("); for(i=0;i<n-1;i++) { System.out.print(a[i]+","); } //Printing the average of the marks// System.out.println(a[i]+") ="+avg/n); } } |
Output:-
In the above program, we have first initialized the required variable.
![](https://www.w3adda.com/wp-content/uploads/2021/09/1-19.jpg)
- i = it will hold the integer value.
- average = it will hold the float value.
- a = it will hold the integer value.
Input number of subjects and the marks from the user.
Program Logic Code.
![](https://www.w3adda.com/wp-content/uploads/2021/09/3-17.jpg)
Printing output.