Java program to accept the name of a person and guess the gender based on following Table.
Condition |
Gender |
Start with “mr.” |
Male |
Start with “miss” |
Female |
Start with “mrs” |
Married Female |
Ends with “Kumari” |
Female |
Else |
Cannot Determine |
import java.util.Scanner;
public class demo{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String: ");
String str = sc.nextLine();
sc.close();
String strArray[] = str.split(" ");
String status;
switch(strArray[0]) {
case("mr"):
status ="male";
break;
case("miss"):
status = "female";
break;
case("mrs"):
status = "maried";
break;
default:
switch(strArray[strArray.length-1]) {
case("kumar"):
status ="male";
break;
case("kumari"):
status = "female";
break;
default:
status = "Cannot Determine";
break;
}
break;
}
System.out.print(status);
}
}
Comments
Post a Comment