Student Mark Calculation in Java


If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

  • The program starts by importing the java.util.Scanner package, which allows the user to input data into the program.
  • Then, it declares seven variables of int and float data types - s1, s2, s3, s4, s5 (marks obtained in each subject), total (total marks obtained), and per (percentage obtained).
  • The program then prompts the user to enter the marks obtained in each subject by displaying the message "Enter the Five Subject Mark :". It takes the input using the Scanner object and stores it in the respective variables.
  • Next, the program calculates the total marks obtained by adding the marks obtained in all five subjects.
  • The program then calculates the per percentage obtained by dividing the total marks obtained by 5 (since there are five subjects) and storing the result in a float variable to get the decimal point value.
  • Finally, the program displays the total marks and per percentage obtained using the System.out.println() method.

Overall, this program is a basic example of how Java can be used to perform simple mathematical operations and input/output operations.


Source Code

import java.util.Scanner;
class Student_Mark
{
	public static void main(String arga[])
	{
		int s1,s2,s3,s4,s5,total;
		float per;
		Scanner input = new Scanner(System.in);
		System.out.println("Enter the Five Subject Mark :");
		s1 = input.nextInt();
		s2 = input.nextInt();
		s3 = input.nextInt();
		s4 = input.nextInt();
		s5 = input.nextInt();
		total = s1+s2+s3+s4+s5;
		per = total/5;
		System.out.println("Total : "+total);
		System.out.println("Percentage : "+per);
	}
}

Output

Enter the Five Subject Mark :
89
56
97
88
92
Total : 422
Percentage : 84.0