Student mark sheet program in Java
In this post, you will learn how to calculate the total marks and grade of a student using the Java programming language.
The given Java program allows a user to manually enter student details, i.e., name, rollno, and marks for three subjects, and then calculate the percentage of the student based on the marks of those three subjects, and then calculate the grade using this range.
80 or above A grade
60 or above B grade
45 or above C grade
35 or above D grade
Less than 35 Fail
We used if-else statements in this program. If else conditions, check for a mark for a particular grade, and if it is true, then print the grade and omit all the other conditions.
import java.util.Scanner;
public class Marksheet
{
public static void main(String[] args)
{
int n,rollno, total = 0, percentage;
Scanner scn = new Scanner(System.in);
System.out.println("Enter the Student roll number : ");
rollno = scn.nextInt();
System.out.println("Enter the Student name : ");
String name = scn.next();
System.out.println("Enter no. of subject : ");
n = scn.nextInt();
int marks[] = new int[n];
System.out.println("Enter marks out of 100 :");
for(int i = 0; i < n; i++)
{
marks[i] = scn.nextInt();
total = total + marks[i];
}
percentage = total / n;
System.out.println("The total mark : "+total);
System.out.println("The percentage : "+percentage);
// calculating grade
if(percentage > 80){
System.out.println("Grade : A");
}
else if(percentage>=60){
System.out.println("Grade : B");
}
else if(percentage>=45){
System.out.println("Grade : C");
}
else if(percentage>=35){
System.out.println("Grade : D");
}
else {
System.out.println("Fail");
}
}
}
Output of the above code:
Enter the Student roll number : 101
Enter the Student name : Priska
Enter no. of subject : 3
Enter marks out of 100 :98 95 93
The total mark : 286
The percentage : 95
Grade : A
Related Articles
Enum from string JavaJava enum
Sort array in ascending order Java
String reverse in Java
Count vowels in a string Java
Java compare two strings
Java string split multiple delimiters
Char array to string Java
Java find largest of three numbers
Vowel and Consonant program in Java
Star pattern programs in Java
Number pattern programs in Java
Java program to find area of rectangle
Matrix multiplication in Java
Electricity bill program in Java
Java program to find area of triangle
Area of circle program in Java
Remove duplicate elements from array in Java
Capitalize first letter of each word Java
Convert binary to decimal in Java
Convert decimal to binary in Java
Convert decimal to octal in Java
Convert decimal to hexadecimal in Java
Simple interest program in Java