Calculate Student Percentage and Print Division in Java


The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a division as per the following rules: Write a program to calculate the division obtained by the student

  • Percentage above or equal to 60 - First division
  • Percentage between 50 and 59 - Second division
  • Percentage between 40 and 49 - Third division
  • Percentage less than 40 – Fail

This is a Java program that calculates the total marks and percentage of a student based on their input for five subjects, and then determines their division based on the percentage.

  • The program starts by importing the Scanner class, which is used to take input from the user. Then, it prompts the user to enter the marks for five subjects. It reads in these marks using nextInt() method of the Scanner class and stores them in separate variables.
  • After this, it calculates the total marks by adding all the subject marks together and calculates the percentage by dividing the total marks by 5. Note that since tot and 5 are both integers, integer division is used, which means the fractional part of the division is discarded.
  • Finally, the program uses if-else statements to determine the student's division based on their percentage. If the percentage is 60 or above, the student is in the first division. If the percentage is between 50 and 59, the student is in the second division. If the percentage is between 40 and 49, the student is in the third division. Otherwise, the student has failed.

Source Code

import java.util.Scanner;
class Student_Division
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter The Five Subject Marks :");
		int m1 = input.nextInt();
		int m2 = input.nextInt();
		int m3 = input.nextInt();
		int m4 = input.nextInt();
		int m5 = input.nextInt();
		int tot = m1+m2+m3+m4+m5;
		float per = tot/5;
		System.out.println("Total :"+tot);
		System.out.println("Percentage :"+per);	
		if(per>=60)
		{			
			System.out.println("First Division.");
		}
		else if(per>=50 && per<=59)
		{			
			System.out.println("Second Division.");
		}
		else if(per>=40 && per<=49)
		{			
			System.out.println("Third  Division.");
		}
		else
		{			
			System.out.println("Fail.");
		}
	}
}

Output

Enter The Five Subject Marks :
56
43
75
68
70
Total :312
Percentage :62.0
First Division.

Example Programs