Gender_game make with java produced by Indranil Bhattacharjee.

Welcome My Study Global

write a program in java select gender. If gender 'm'for male then he is called mr. he's name or if gender 'f' for female then program asked she's married or unmarried .If she's married then called mrs.she's title or she's unmarried then called she,s full name.

import java.util.Scanner;

class Gender {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.print("What is your gender (M or F): ");
        char g = sc.next().charAt(0);
        sc.nextLine();
        switch (g) {
            case 'M':
                System.out.print("First name: ");
                String h = sc.nextLine();
                System.out.print("Last name: ");
                String b = sc.nextLine();
                System.out.print("Age: ");
                int Age = sc.nextInt();
                if (Age >= 20) {
                    System.out.printf("\nThen I shall call you Mr. %s.", b);
                    break;
                } else {
                    System.out.printf("\nThen I shall call you %s %s.", h, b);
                    break;
                }
            case 'F':
                System.out.print("First name: ");
                String f = sc.nextLine();
                System.out.print("Last name: ");
                String l = sc.nextLine();
                System.out.print("Age: ");
                int j = sc.nextInt();
                if (j >= 20) {
                    System.out.printf("\nAre you married, %s (y or n)? ", f);
                    char y = sc.next().charAt(0);
                    switch (y) {
                        case 'y':
                            System.out.printf("\nThen I shall call you Mrs. %s.", l);
                            break;
                        default:
                            System.out.printf("\nThen I shall call you Ms. %s.", l);
                            break;

                    }
                } else {
                    System.out.printf("\nThen I shall call you %s %s.", f, l);

                }
                break;
            default:
                System.out.println("Invalid Gender");
        }

    }

}

Output is :-
















Comments