Write a program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
This Java program takes five subject marks as input from the user and calculates the total and percentage of those marks. It also assigns a grade based on the percentage obtained.
Here is how the program works:
Note that the program assumes that the user will enter integer values for the marks, and that the percentage calculated will be a whole number. If you want to calculate a more precise percentage, you can change the data type of the variable per to float or double, and use floating-point division instead of integer division in the calculation.
import java.util.Scanner; class Student_Grade { 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>=90) System.out.println("Grade A"); else if(per>=80) System.out.println("Grade B"); else if(per>=70) System.out.println("Grade C"); else if(per>=60) System.out.println("Grade D"); else if(per>=40) System.out.println("Grade E"); else System.out.println("Grade F"); } }
Enter The Five Subject Marks : 65 89 82 95 85 Total :416 Percentage :83.0 Grade B
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions