Program to calculate the percentage of given 3 subjects and print the appropriate grade.
The if construct:
if(condition)
{
// The desired operation
}
The if-else construct:
if(condition)
{
// The desired operation
}else{
// The desired operation
}
if - else if - else
if(condition1)
{
// The desired operation
}else if(condition2)
{
// The desired operation
}else
{
// The desired operation
}
if(condition)
{
// The desired operation
}
The if-else construct:
if(condition)
{
// The desired operation
}else{
// The desired operation
}
if - else if - else
if(condition1)
{
// The desired operation
}else if(condition2)
{
// The desired operation
}else
{
// The desired operation
}
public class Grade { public static void main(String args[]) { int phy,chem,math; double a; phy=69; chem=81; math=80; a=(phy+chem+math)/3; System.out.println("Percentage: "+a); if(a>=75) { System.out.println("Grade:A"); } else if(a>=50) { System.out.println("Grade:B"); } else if(a>=35) { System.out.println("Grade:C"); } else { System.out.println("Fail"); } } } OUTPUT Percentage: 76.0 Grade:A