Monday, 23 March 2015

Identify First Name and Surname (Bin and Binti) in Java

Maybe in Islam name, people has father's name after their name. For man, use "bin" and for woman use "binti". And how to identify name in Java using bin or binti??

boolean found = Arrays.asList(name.split(" ")).contains(keyword);

Code above is to identify whether in that name contain words in keyword. if the value is true then execute the program. If false, then execute something else.

here is the code in Java, I used array and use keyword to determine.

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Achmad Zulkarnain
 */
public class Surname {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        String keyword = "binti";

        System.out.print("Please enter your full name> ");
        String name = in.nextLine();

        boolean found = Arrays.asList(name.split(" ")).contains(keyword);
        if (found) {
            int Index = name.indexOf("binti");
            System.out.println("Hello your name is " + name.substring(0, (Index)));
            System.out.println("And your father's name is " + name.substring(Index + 6));
        } else {
            int Index = name.indexOf("bin");
            System.out.println("Hello your name is " + name.substring(0, (Index)));
            System.out.println("And your father's name is " + name.substring(Index + 4));
        }
    }
}



Share:

0 comments:

Post a Comment