# Java Program To Calculate Average Marks | 5 Methods

Java program to calculate the average of marks. Here we cover five simple ways to find out the average of marks in Java programming. If you know the basics of coding, you can even write more than 5+ ways. However, as a newbie, we share the program in 5 different ways. Do check it out. Our database consists of more than 100+ sample Java programs. The following program is written in five simple ways: standard values, class, by using method, by using command line arguments.

So, How to calculate the average of marks in math?

A: That’s quite simple, for example, consider you have just completed your sem exams, and the result announced as:

• Maths                       –  75
• Science                      –  55
• Operating Systems  –  80
• Dataware house       –  75

• Now, sum up all      –      285/4 = 71.25 ( Your average marks )

So, your average of entire subjects are  = 71.25 ( Formula stated below) That’s a standard and the only way to calculate your average of marks. Now, check out the following programs.

## Average Marks Java Program Five Simple Ways

Example Code -1: ( using standard values )

• Basic version with standard values. Here we took Int n=5; it’s all up to you. And also check output screen.

• OutPut :

### Java Program Calculate Average Marks Using Arrays

• Java code for obtaining an average of marks taking inputs through Scanner class. Here it is: #Inputs Through Scanner Class#
• Output:

For example purpose, we have executed the above program with three different outputs as given below. You need to enter the total number of subjects that you need to calculate or find and followed by marks. The console will display the output as follows:

#### Average Marks Using Command Line Arguments

•  Here we are using command line arguments if you have no idea about then check out that link. As like above, the inputs are taken through scanner class, whereas here inputs are taking through command line arguments.
• Output :

This is how the actual output screen will look alike, c:\users\goutham\desktop ( Don’t consider this, because we are executed the above code on our system, so we copied the output here ). Output console may vary code to code.

##### Java Program Average Marks Using Class
• Java program for calculating an average of marks through creating a separate class(AverageCalculation) and taking inputs through scanner class. Check out the code.
• Output: ( 2 Sample outputs )

###### Using Method
• Java code for calculating the average of marks using a user-defined method
• Output: