Selection - Nested If
Selection - Nested If
Ask users to enter age, gender ( M or F ), marital status ( Y or N ) and then using
If the employee is female, then she will work only in urban areas.
anywhere
If the employee is male and age is between 40 t0 60 then he will work in urban
areas only.
1)IPO
O: work areas
2) PSEUDOCODE
Start
If (gender = F)
Else
Print “ Error”
End if
End if
Stop
3) FLOWCHART
4)JAVA CODING
i) NORMAL CODING
//Author ili
//nested if question 3
import java.util.*;
class Area{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter age");
int age = sc.nextInt();
if(sex == 'F') {
System.out.println("you will work area only in urban
areas");
}
if(sex == 'M') {
if((age >= 20) && (age < 40)) {
System.out.println("You may work anywhere");
}
else if((age >= 40) && (age < 60)) {
System.out.println("You will work only in urban
areas");
}
else {
System.out.println("ERROR");
}
}
}
}
ii) USING METHOD
//Author ili
//nested if question 3
import java.util.*;
class WorkArea{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter age");
int age = sc.nextInt();
if(sex == 'F') {
System.out.println("you will work area only in urban areas");
}
if(sex == 'M') {
if((age >= 20) && (age < 40)) {
System.out.println("You may work anywhere");
}
else if((age >= 40) && (age < 60)) {
System.out.println("You will work only in urban areas");
}
else {
System.out.println("ERROR");
}
}
}
}