-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedIfStatement.java
More file actions
43 lines (37 loc) · 1.06 KB
/
Copy pathNestedIfStatement.java
File metadata and controls
43 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Phase1_CoreLanguage.DecisionMaking;
/**A nested if is an if statement that is the target of another if or else.
* Nested if statements means an if statement inside an if statement.
* Yes, java allows us to nest if statements within if statements.
* i.e, we can place an if statement inside another if statement.
*
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}**/
public class NestedIfStatement {
public static void main(String args[])
{
int i = 10;
if (i == 10)
{
// First if statement
if (i < 15)
System.out.println("i is smaller than 15");
// Nested - if statement
// Will only be executed if statement above
// it is true
if (i < 12)
System.out.println("i is smaller than 12 too");
else
System.out.println("i is greater than 15");
}
}
//OUTPUT
//i is smaller than 15
//i is smaller than 12 too
}