Program to find out code of grade and percentage calculator in java of a student when the marks of 6 subjects are given.
In this program, we calculate the grade and percentage of students according to 6 subjects marks by the given below methods by if-else loop concepts basic to advance loop in java
best if else if loop example with explanation
The method of assigning grades is –
percentage>=85 grade=A
percentage<85 and percentage>=70 grade=B
percentage<70 and percentage>=55 grade=C
percentage<55 and percentage>=40 grade=D
percentage<40 grade=E
public class Percentagefile {public static void main(String[] args) {
float m1, m2, m3, m4, m5, m6, total, percentage;
char grade = ‘Z’;
Scanner in = new Scanner(System.in);System.out.println(“Please enter marks out 100 of Subject 1”);
m1 = in.nextInt();
System.out.println(“Please enter marks out 100 of Subject 2”);
m2 = in.nextInt();
System.out.println(“Please enter marks out 100 of Subject 3”);
m3 = in.nextInt();
System.out.println(“Please enter marks out 100 of Subject 4”);
m4 = in.nextInt();
System.out.println(“Please enter marks out 100 of Subject 5”);
m5 = in.nextInt();
System.out.println(“Please enter marks out 100 of Subject 6”);
m6 = in.nextInt();
// Total all 6 subject marks
total = m1 + m2 + m3 + m4 + m5 + m6;
// Calculate percentage of All Subject
percentage = total / 6;
if (percentage > 33 && percentage < 100) {
if (percentage >= 100) {
System.out.println(“Your percentage is invaild.”);
} else if (percentage >= 85) {
grade = ‘A’;
} else if (percentage >= 70) {
grade = ‘B’;
} else if (percentage >= 55) {
grade = ‘C’;
} else if (percentage >= 40) {
grade = ‘D’;
} else {
grade = ‘E’;
}
System.out.println(“Your score ” + percentage + “% and your grade is ” + grade + “”);
} else {
System.out.println(“You are Fail or You Enter Invaild Marks”);
}
}
}
Suppose Student S1 finds the following marks:
Subject 1=70, Subject 2 =50, Subject 3 = 80,
Subject 4 = 76, Subject 5 = 56, Subject 6 = 78,
output:
Please enter marks out 100 of Subject 1
70
Please enter marks out 100 of Subject 2
50
Please enter marks out 100 of Subject 3
80
Please enter marks out 100 of Subject 4
76
Please enter marks out 100 of Subject 5
56
Please enter marks out 100 of Subject 6
78
Your score 68.333336% and your grade is C
BUILD SUCCESSFUL (total time: 15 seconds)
I make this programming and hope you are like the post if are you like the post you can please comment and share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form is given on the page right side.
Same Percentage Program Code in C language
Same Percentage Program Code in C++ language
Share your experience with this post,
Thank You!