Calculate Marks Using Java
In this Java programming tutorial, we will learn how to create a program to calculate the marks of different subjects.
To begin with, we will create a class named "MarksCalculator" and define the main() method inside it. We will use the Scanner class to take input from the user.
We will declare variables to store the marks of different subjects and then take input from the user using the Scanner class. After taking input, we will calculate the total marks and percentage of the student.
Finally, we will display the total marks and percentage on the screen using the System.out.println() method.
PROGRAM :-
import java.util.Scanner;
public class marks {
public static void main(String[] args) {
System.out.println("...Enter your marks...");
Scanner a=new Scanner(System.in);
System.out.print("Hindi : ");
int num1=a.nextInt();
System.out.print("English : ");
int num2=a.nextInt();
System.out.print("Physics : ");
int num3=a.nextInt();
System.out.print("Chemistry : ");
int num4=a.nextInt();
System.out.print("Mathematics : ");
int num5=a.nextInt();
int sum = num1 + num2 + num3 + num4 + num5;
System.out.println("Total Marks : " +sum);
float per= sum/5;
System.out.println("Percentage : " +per+"%");
if(per>=80){
System.out.println("Outstanding Performence");
}
else if(per>=60||per<80){
System.out.println("First Class");
}
else if(per>=50||per<60){
System.out.println("Second Class");
}
else if(per>=40||per<50){
System.out.println("Third Class");
}
else
System.out.println("Failed");
}
}
OUTPUT :-
...Enter your marks...
Hindi : 67
English : 56
Physics : 45
Chemistry : 66
Mathematics : 56
Total Marks : 290
Percentage : 58.0%
First Class
Once you compile and run the program, you can enter the marks of the three subjects and get the total marks and percentage as output. This program can be used as a base to create more complex programs for calculating marks and grades.
0 Comments