Page 124 - CA_Blue( J )_Class10
P. 124
To input one number and print whether the number is a positive number or negative number or
Program 5
zero.
1 import java.util.*;
2 class check_number
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int n;
8 System.out.print("Enter a number : ");
9 n=sc.nextInt();
10 if(n>0)
11 System.out.println(n + " is a positive number.");
12
13 else if(n<0)
14 System.out.println(n + " is a negative number.");
15 else
16 System.out.println(n + " is a positive number.");
17 }
18 }
You will get the following output:
7.2.5 Nested if Statement
Certain situation demands the if statement within another if statement. The if statement inside another if statement
is called nested if. The inner if statement will execute only if the outer if statement evaluates to true. If the outer
if statement does not satisfy, then the else part of the outer if statement will execute. The syntax of the nested if
statement is:
if(Condition 1)
{
if(Condition 2)
Statement 1;
else
Statement 2;
}
122122 Touchpad Computer Applications-X

