KnowledgeBoat Logo

Computer Applications

Write a Java program in which you input students name, class, roll number, and marks in 5 subjects. Find out the total marks, percentage, and grade according to the following table.

PercentageGrade
>= 90A+
>= 80 and < 90A
>= 70 and < 80B+
>= 60 and < 70B
>= 50 and < 60C
>= 40 and < 50D
< 40E

Java

Java Conditional Stmts

93 Likes

Answer

import java.util.Scanner;

public class KboatStudentGrades
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name of student: ");
        String n = in.nextLine();
        System.out.print("Enter class of student: ");
        int c = in.nextInt();
        System.out.print("Enter roll no of student: ");
        int r = in.nextInt();
        System.out.print("Enter marks in 1st subject: ");
        int m1 = in.nextInt();
        System.out.print("Enter marks in 2nd subject: ");
        int m2 = in.nextInt();
        System.out.print("Enter marks in 3rd subject: ");
        int m3 = in.nextInt();
        System.out.print("Enter marks in 4th subject: ");
        int m4 = in.nextInt();
        System.out.print("Enter marks in 5th subject: ");
        int m5 = in.nextInt();
        int t = m1 + m2 + m3 + m4 + m5;
        double p = t / 500.0 * 100.0;
        String g = "";
        if (p >= 90)
            g = "A+";
        else if (p >= 80)
            g = "A";
        else if (p >=70)
            g = "B+";
        else if (p >= 60)
            g = "B";
        else if (p >= 50)
            g = "C";
        else if (p >= 40)
            g = "D";
        else
            g = "E";
            
        System.out.println("Total Marks = " + t);
        System.out.println("Percentage = " + p);
        System.out.println("Grade = " + g);
    }
}

Output

BlueJ output of Write a Java program in which you input students name, class, roll number, and marks in 5 subjects. Find out the total marks, percentage, and grade according to the following table.

Answered By

39 Likes


Related Questions