3 Replies Latest reply: Nov 6, 2013 3:22 AM by PhHein RSS

    Comparing Names


      Hey guys, I'm new to Java and would like some assistance in an algorithm. I'm trying to create an algorithm that compares the first names of two people, which goes ahead and cancels similar characters and then counts the remaining characters to give a 0 if the remaining characters are even and a 1 if the remaining characters odd. Thank you

        • 1. Re: Comparing Names

          How would you do it with paper and pen? Define similar characters. Define even and odd characters.

          Your post is too vague to give a decent reply, plus you didn't even ask a question.

          • 2. Re: Comparing Names

            Here is a rough example. I read two names from a user, say Daniel and Mark(case is irrelevant). The algorithm compares the two names and eliminates similar characters in both names. In this instance "a" is found both in Daniel and in Mark so it eliminated. Since their are no more two similar characters in the remaining string, the remaining characters are counted i.e (dniel) and (mrk). If we count the characters (dniel) is made up of five characters hence odd, the program should output 1. Similarly (mrk) are three characters hence odd and 1 is printed. If we concatenate them we get 11 which should be the final output

            • 3. Re: Comparing Names

              OK, you still have not asked a question. Have a look at the String API for methods that give you a character from a String, a method to remove/replace a character in a String, a method to get the length of the string etc.

              Write down in pseudocode what your program's simple steps are and continue from there. I will not provide any code for you. But I'll gladly help if you get stuck with coding.