The document presents a Java program that inputs marks for five subjects and calculates the average to determine the corresponding grade. It uses a loop to gather input and conditional statements to assign grades based on the average marks. The grades are categorized as A, B, or C based on the average score thresholds.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views2 pages
Grade
The document presents a Java program that inputs marks for five subjects and calculates the average to determine the corresponding grade. It uses a loop to gather input and conditional statements to assign grades based on the average marks. The grades are categorized as A, B, or C based on the average score thresholds.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Program to input marks of subjects and display the grade
import java.util.*;
import java.io.*;
import java.lang.*;
//Importing Packages
public class Grade //declaring class
{ //opening braces of the class
public static void main(String[]args) //declaring main method
{//opening braces of the main method
int marks=0,x; //declaring variables
Scanner pa = new Scanner(System.in); //declaring scanner class
System.out.println("Enter the marks of five subjects");
for(int i=1;i<=5;i++)
{ //opening braces of the loop
x = pa.nextInt(); //inputting the marks by the user
marks=marks+x; // storing marks
x=0;
}//closing braces of the loop
int avg = marks/5; //averaging the marks in five subjects
if(avg<=40)
System.out.println("Grade is C");
else if(avg>40 && avg<=70)
System.out.println("Grade is B");
else
System.out.println("Grade is A");
} //closing braces of main method
}//closing braces of the class
VARIABLE DATA TYPE FUNCTION
marks Integer To store the total marks entered by the user x Integer To take input 5 times i Integer To run loop to take 5 inputs avg Integer To store the average