|
Nested If Statement

In this section you will study about the Nested-if Statement in jsp.
Nested If statement means to use the if statement inside the other if
statement. Here we
are providing you an example using Nested-If statement. In the example, we want
to display the reciprocal of a number only if that number is positive. So, an
integer variable number is initialized to 4.
Here is the code of nestedIf.jsp
<HTML>
<HEAD>
<TITLE>Nested if Statement Example</TITLE>
</HEAD>
<BODY>
<H2>Nested if Statement Example</H2>
<%
double number = 4;
if (number != 0) {
if (number> 0){
out.println("The result = " + (1 / number));
}
else
out.println("A positive number is required.");
}
%>
</BODY>
</HTML>
|
Output will be displayed as:

Download source Code

|