Output error in comparing characters from two strings

Posted by Andrew Martin on Stack Overflow See other posts from Stack Overflow or by Andrew Martin
Published on 2012-11-15T22:44:42Z Indexed on 2012/11/15 23:00 UTC
Read the original article Hit count: 150

Filed under:
|
|
|

I'm stuck with my a piece of code I'm creating. My IDE is Eclipse and when I use its debugging feature, to trace what's happening on each line, it outputs perfectly. However, when I click the "run" project, it just outputs a blank screen:

public static void compareInterests(Client[] clientDetails)
{
    int interests = 0;

    for (int p = 0; p < numberOfClients; p++)
    {
        for (int q = 0; q < numberOfClients; q++)
        {
            String a = clientDetails[p].getClientInterests();
            String b = clientDetails[q].getClientInterests();

            int count = 0;
            while (count < a.length())
            {
                if (a.charAt(count) == b.charAt(count))
                    interests++;
                count++;
            }

            if ((interests >= 3) && (clientDetails[p].getClientName() != clientDetails[q].getClientName()))
                System.out.print (clientDetails[p].getClientName() + " is compatible with " + clientDetails[q].getClientName());
            interests = 0;
        }
    }
}

The code is designed to import an object array which contains information on a client's name and a client's interests. The client's interests are stored in the format "01010", where each 1 means they are interested in that activity, each 0 means they are not.

My code compares each character of every client's string with every other client's string and outputs the results for all client's that don't have the same name and have three or more interests in common.

When I run this code through Java's debugger, it outputs fine - but when I click run project or compile, I just get a blank screen.

Any ideas?

© Stack Overflow or respective owner

Related posts about java

Related posts about string