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:

Percentage above or equal to 75 – Honors

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

Write a program to calculate the division obtained by the student,Create program in java.

 
				
					import java.util.Scanner;

public class DivisionCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Array to hold marks of 5 subjects
        int[] marks = new int[5];
        int totalMarks = 0;
        
        // Input marks for 5 subjects
        System.out.println("Enter marks for 5 subjects: ");
        for (int i = 0; i < 5; i++) {
            System.out.print("Subject " + (i + 1) + ": ");
            marks[i] = scanner.nextInt();
            totalMarks += marks[i];
        }

        // Calculate percentage
        double percentage = totalMarks / 5.0;

        // Determine the division based on percentage
        String division;
        if (percentage >= 75) {
            division = "Honors";
        } else if (percentage >= 60) {
            division = "First Division";
        } else if (percentage >= 50) {
            division = "Second Division";
        } else if (percentage >= 40) {
            division = "Third Division";
        } else {
            division = "Fail";
        }

        // Display the result
        System.out.println("Total Marks: " + totalMarks);
        System.out.println("Percentage: " + percentage + "%");
        System.out.println("Division: " + division);
    }
}

				
			

Explanation:

  1. Import Scanner: We import the Scanner class to take input from the user.
  2. Main Method: We define the main method where the execution begins.
  3. Array for Marks: We create an array to store the marks of 5 subjects.
  4. Input Marks: We use a loop to prompt the user to enter marks for each of the 5 subjects, and we calculate the total marks.
  5. Calculate Percentage: The percentage is calculated by dividing the total marks by the number of subjects (5).
  6. Determine Division:
    • If the percentage is 75 or above, the division is “Honors”.
    • If the percentage is between 60 and 74.99, the division is “First Division”.
    • If the percentage is between 50 and 59.99, the division is “Second Division”.
    • If the percentage is between 40 and 49.99, the division is “Third Division”.
    • If the percentage is below 40, the division is “Fail”.
  7. Output: The program prints the total marks, percentage, and the division obtained by the student.

You can run this program in any Java IDE or command-line environment and input different marks to test the division calculation.

Another Example

				
					import java.util.Scanner;

public class StudentDivision {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        float[] marks = new float[5];
        float total = 0;
        float percentage;

        // Input marks for 5 subjects
        System.out.println("Enter the marks obtained in 5 subjects: ");
        for (int i = 0; i < 5; i++) {
            System.out.print("Subject " + (i + 1) + ": ");
            marks[i] = scanner.nextFloat();
            total += marks[i];
        }

        // Calculate percentage
        percentage = (total / 500) * 100;

        // Determine division based on percentage
        System.out.println("Total Marks = " + total);
        System.out.println("Percentage = " + percentage + "%");

        if (percentage >= 75) {
            System.out.println("Division: Honors");
        } else if (percentage >= 60) {
            System.out.println("Division: First Division");
        } else if (percentage >= 50) {
            System.out.println("Division: Second Division");
        } else if (percentage >= 40) {
            System.out.println("Division: Third Division");
        } else {
            System.out.println("Division: Fail");
        }

        scanner.close();
    }
}

				
			
prime number

Explanation:

  1. Importing Scanner Class:

    • The Scanner class from java.util package is imported to take input from the user.
  2. Variable Declaration:

    • marks array to store the marks of 5 subjects.
    • total to store the sum of all marks.
    • percentage to store the calculated percentage.
  3. Input Marks:

    • A loop is used to take input for the 5 subjects and simultaneously sum them up into the total.
  4. Calculate Percentage:

    • The percentage is calculated by dividing the total by 500 (since there are 5 subjects, and each subject is assumed to be out of 100) and then multiplying by 100.
  5. Determine Division:

    • Based on the percentage calculated, the program prints the division according to the given rules.

This Java program will take the marks of 5 subjects from the user, calculate the total and percentage, and then determine and print the division the student falls into.

Scroll to Top