Respuesta :
Answer:
The program to this question can be given as:
Program:
import java.util.*; //import package.
public class Main //define class
{
public static void main(String[] ar) //define main method
{
int grade=0,subject,i,sum=0,total = 0; //define variables
System.out.print("Enter the number of subject:"); //message
Scanner ob = new Scanner(System.in); //creating Scanner class object.
subject= ob.nextInt(); //taking input from user.
System.out.println("Enter grades in number:");
for(i=1;i<=subject;i++) //loop.
{
grade = ob.nextInt(); //input grades.
sum=sum+grade; //add grades.
}
//System.out.println("sum:"+sum);
total=(sum*100)/(subject*100); //persentage
//System.out.println("persentage:"+total);
//conditional statement
System.out.print("your grade :");
if(total>=90) //check persentage
{
System.out.print("A grade"); //print message
}
else if(total>=80)
{
System.out.print("B grade");
}
else if(total >=70)
{
System.out.print("C grade");
}
else if(total >=60)
{
System.out.print("D grade");
}
else
{
System.out.print("E grade");
}
}
}
Output:
Enter the number of subject: 3
Enter grades in number:
79
76
59
your grade :C grade
Explanation:
In the above program firstly we import the package for user input then we declare the class name main in this class we declare the main method in the main main method we declare the variable. Then we create a scanner class object for user input the we take input from the user and add all number and put the value into the sum variable and the we calculate the percentage and put into the total variable then we the conditional statement in this part we check the value between the different parameters if the value match then we print the grade.