Nested if Statement

Nested if Statement
If a if statement is used within on if statement then such a control structure is called as nested if.

Syntax
if(condition)
{
if(condition)
{
//statement-if condition is true;
}
}

Program

Write a program to print total marks of student from given 5 subject, also print result if student is passed
class test
{
public static void main(String args[])
{
int a=65,b=70,c=75,d=60,e=78,total;
double per;
total=a+b+c+d+e;
System.out.println(“Total marks=”+total);
per=total/5;
if(a>=40 && b>=40 && c>=40 && d>=40 && e>=40)
{
if(per>40)
{
System.out.println(“You are Passed”);
}
}
}
}

Output:
Total marks=348
You are Passed

Leave a Reply

Your email address will not be published. Required fields are marked *