Write a program to that asks the user to enter user's Name , Father Name , Age ,Gender,
CNIC, Phone & stores each & every thing in separate variables
then checks where the person is a Male or a Female ,
incase the person is a male then he must be 25 or more to cast the Vote else he is not eligible
to caste the vote.
and incase the person is a Female then he must be 18 or more to cast the Vote else he is not
eligible to caste the vote.
Note python Code need
Answers
Answer:
I am writing the code for the problem below where the conditions are given using if else.
import java.util.*;
class Ideone
{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
// taking input from user
System.out.println("Enter age");
int age = sc.nextInt();
System.out.println("Enter sex: M/F");
int sex = sc.next().charAt(0);
System.out.println("Are you married? Y/N");
int married = sc.next().charAt(0);
// checking if user is female
if(sex == 'F') {
System.out.println("You will work only in urban areas");
}
// checking if user is male
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");
Answer:
import java.util.*;
class Ideone
{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
// taking input from user
System.out.println("Enter age");
int age = sc.nextInt();
System.out.println("Enter sex: M/F");
int sex = sc.next().charAt(0);
System.out.println("Are you married? Y/N");
int married = sc.next().charAt(0);
// checking if user is female
if(sex == 'F') {
System.out.println("You will work only in urban areas");
}
// checking if user is male
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");
}
}
}
}