Java Program To Calculate Average Of Marks | 5 Methods
Beginners Programs :

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 written in five simple ways: standard values, class, by using method, by using command line arguments.

Table Of Contents:

Average Of Marks 5 Different Ways
1.Using standard Values
2.Taking Inputs Through Scanner Class
3.Using Command Line Arguments
4.Create Separate class
5.User Define Method

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)

java program for average of marks

That’s a standard and 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 command line arguments in java 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 average of marks using a user defined method 
  • Output: 

If you need any more information or any doubts or bugs from the above codes, do leave a comment here.

#HappyCoding  #JavaTutoring  #BeginnersPrograms