-4

So below I have and method that returns true if the second condition is met. However, I want to return false if the first condition is met. However, the problem I get is it returns false all the times.

public static boolean matching(Request a, Request b) {
        if (a.info[2].equals("*") & b.info[2].equals("*")) {
            return false;
        }
        return ((a.info[1].equals(b.info[1]) && a.info[2].equals(b.info[2])) || (a.info[1]
                .equals(b.info[1]) && a.info[2].equals("*") || b.info[2]
                    .equals("*")));

    }
Anon
  • 1
  • 5
  • Could you please show us an example of input you're expecting to return `true`? – ssantos Apr 25 '15 at 21:03
  • If it returns false all the time, then either the first condition is true, or the second one is false. Use your debugger to find out why. We don't have any clue of the content of those arrays. – JB Nizet Apr 25 '15 at 21:07
  • yes I put && and basically its a server program. If it is has * on both then it should return false and wait. It does that. However, if its not star it still will return false and wait – Anon Apr 25 '15 at 21:08
  • Please try to describe the condition you want to achieve in understandable examples (I am sure it would fix your problem by just stating it properly). – eckes Apr 25 '15 at 21:20
  • @JayPatel, please, fix the `&` in your answer in order to avoid confusion and let new readers to help you faster. – ssantos Apr 25 '15 at 21:24

1 Answers1

-1

Without trying to understand your whole conditional sentences, I'm guessing you have a typo here.-

if (a.info[2].equals("*") & b.info[2].equals("*")) {

and you meant

if (a.info[2].equals("*") && b.info[2].equals("*")) {

instead.

You can take a look to this old thread for further information.

EDIT

If the problem persists, chances are that there're issues on the second conditional sentence. The best you can do is setting a breakpoint to display all relevant values during runtime; you should easily see what's going wrong.

Community
  • 1
  • 1
ssantos
  • 16,001
  • 7
  • 50
  • 70
  • Ok so that was not the problem. I was just messing around to see what could be the cause of the issue. – Anon Apr 25 '15 at 21:05
  • if that not the problem then what you mean by @JayPatel messing around and around what .. ? – Ankur Anand Apr 25 '15 at 21:07
  • @JayPatel, an example of input you're expecting to return `true`, and `Request` class code could help. Please, double check as well what condition is goes through the execution thread. – ssantos Apr 25 '15 at 21:08
  • The single `"&"` is definitely not the problem. So you should either update your answer if you know the problem or delete it. – Tom Apr 26 '15 at 19:29
  • Yeah... I don't know... If I got a coin every time someone says "That's not the problem, I was just messing around and... oh, wait, it looks that's actually the problem" :) – ssantos Apr 27 '15 at 01:31
  • @ssantos Ok, then can you explain how this could be the problem? The first line always checks both expression and the second line "stops" if the first expression is `false`. Since both expressions have no side effect (like calling a method which changes variable states), there can't be any difference. And since it looks like OP doesn't care about this question we won't get the information what the fix for his problem was. :( – Tom May 01 '15 at 07:10