Page 168 - CA_Blue( J )_Class9
P. 168
Program 7 Input 3 numbers and print the smallest number.
1 import java.util.*;
2 class smallest_number
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int a,b,c,s;
8 System.out.print("Enter first number :");
9 a=sc.nextInt();
10 System.out.print("Enter second number :");
11 b=sc.nextInt();
12 System.out.print("Enter third number :");
13 c=sc.nextInt();
14 System.out.println("--------------------------");
15 s=(a<b)? (a<c)?a:c:(b<c)?b:c;
16 System.out.println("Smallest Number :"+s);
17 }
18 }
You will get the following output:
Nested if Statement
Certain situation presents a condition within another condition. To handle such situations, we use nested if
statements where if condition 1 is true, then the internal ‘if’ statement will be executed. If condition 1 does not
satisfy, the else part will be executed.
Syntax:
if(Condition 1)
{
if(Condition 2)
166 Touchpad Computer Applications-IX

