10. Write a Java program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
10. Write a Java program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
Static
Solution :-
class result
{
public static void main(String args[])
{
int che = 55,phy=70,bio=65,maths=85,comp=80,tot,perc;
tot = che+phy+bio+maths+comp;
perc =tot/5;
System.out.println("The total marks your score is :-"+tot);
System.out.println("The percentage you scored is :- "+perc);
if (perc>=90)
{
System.out.println("Your grade is A :- "+perc);
}
else if (perc>=80)
{
System.out.println("Your grade is B :- "+perc);
}
else if (perc>=70)
{
System.out.println("Your grade is C :- "+perc);
}
else if (perc>=60)
{
System.out.println("Your grade is D :- "+perc);
}
else if (perc>=40)
{
System.out.println("Your grade is A :- "+perc);
}
else if (perc<40)
{
System.out.println("Your grade is A :- "+perc);
}
else
{
System.out.println("Fail");
}
}
}
Output :-
Dynamic
Solution :-
import java.util.*;
class result
{
public static void main(String args[])
{
int che,phy,bio,maths,comp,tot,perc;
Scanner in = new Scanner(System.in);
System.out.println("Enter the marks of Physics :- ");
phy =in.nextInt();
System.out.println("Enter the marks of Chemistry :- ");
che =in.nextInt();
System.out.println("Enter the marks of Biology :- ");
bio =in.nextInt();
System.out.println("Enter the marks of Mathematics :- ");
maths =in.nextInt();
System.out.println("Enter the marks of Computer :- ");
comp =in.nextInt();
tot = che+phy+bio+maths+comp;
perc =tot/5;
System.out.println("The total marks your score is :-"+tot);
System.out.println("The percentage you scored is :- "+perc);
if (perc>=90)
{
System.out.println("Your grade is A :- "+perc);
}
else if (perc>=80)
{
System.out.println("Your grade is B :- "+perc);
}
else if (perc>=70)
{
System.out.println("Your grade is C :- "+perc);
}
else if (perc>=60)
{
System.out.println("Your grade is D :- "+perc);
}
else if (perc>=40)
{
System.out.println("Your grade is A :- "+perc);
}
else if (perc<40)
{
System.out.println("Your grade is A :- "+perc);
}
else
{
System.out.println("Fail");
}
}
}
Output :-