Java program to find Total Average and Percentage of Five Papers

In this example, we learn how to write java program to calculate average marks?. We will write a program in Java to find the average and percentage of marks obtained by a student in five papers. Here we will find an average and percentage of marks from five papers. Let see an example,

Logic to Calculate Average Marks and Percentages

Here below I shared step by step guide to find average marks and percentage. So, this logic you can easily use to write java program.

  1. Take input of five papers marks from user and store in a variable named m1, m2, m3, m4 & m5.
  2. Calculate the total of five paper marks and then divide it by total marks of numbers of papers i.e. 500 and store in avg like avg = (m1+m2+m3+m4+m5)/500.
  3. Calculate percentage using perc = avg * 100;
  4. Finally, Print all five papers marks, average marks, and percentage.

Java to find the average and percentage of marks obtained by a student in five papers

The below program ask the user to enter the five papers marks. After getting the value from the user it will an average and percentage of marks from five papers.



import java.util.*; 

class student {

int m1,m2,m3,m4,m5; 
double avg,perc;

  public void get()
  {
    Scanner s=new Scanner(System.in);
    m1=s.nextInt();
    m2=s.nextInt();
    m3=s.nextInt(); 
    m4=s.nextInt(); 
    m5=s.nextInt();
    avg=(m1+m2+m3+m4+m5)/500.0; 
    perc=avg*100;
  }
  public void display()
  {
    System.out.println("m1="+m1); 
    System.out.println("m2="+m2); 
    System.out.println("m3="+m3); 
    System.out.println("m4="+m4); 
    System.out.println("m5="+m5); 
    System.out.println("Average="+avg); 
    System.out.println("Percentage="+perc);
  }
};

public class Student_marks{
  public static void main(String args[])
  {
   student s1=new student(); s1.get();
   s1.display();
  }
}

Output


C:\jdk-12.0.2\bin>javac smarks.java 
C:\jdk-12.0.2\bin>java smarks

 34
 56
 65
 88
 67 
 m1=34 m2=56 m3=65 m4=88 m5=67
 Average=0.62
 Percentage=62.0
That's all about Java to find the average and percentage of marks obtained by a student in five papers.

Happy Coding 😊

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form