mardi 10 décembre 2019

Java: Will if-statments not work if I have two or more conditionals in the statement?

There is probably an obvious answer. This question might have already been asked but I don't know how to word the question. I'm working in Java and in this moment, I am reading the input text from the command line and converting that stuff over to strings.

I am, for sure, inputting the x character into the command line and whether I set the code to

!(first.equals("x")) or (first.equals("x"))

I still get the system.out output text. I noticed that if I remove the || and the following equals snippet it works as intended and continues onto the code. However, I have to have either x or y be options for the first arg string. Can someone please let me know what I am doing wrong. Thanks.

Here is the snippet of code:

private something(String[] args) 
{       
    first = args[0];
    second = args[1];
    third = args[2];

    if ((first.equals("x")) || (first.equals("y")))
    {           
        System.out.println("First is the problem " + first);
    }
}

Here is the ouput:

First is the problem x

Aucun commentaire:

Enregistrer un commentaire