0

Having a hard time understanding why this code won't run as I'm hoping it should. I'm creating a test-checker with 2 arrays, one being a key and the other the user's inputs. I'm stuck trying to verify that the user will be restricted to ONLY inputting "A, B, C, or D". I've tried using booleans, nested if's, and several other methods I've found, but none of them work correctly.

package projects;
public static void main(String[] args) {
    String key[] = {"B", "D","A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};
    String Input[] = new String[20];
    for (int x = 0;  x < 20; x++)
    {
        Input[x] = JOptionPane.showInputDialog(null, "Input Answers (A, B, C, or D)" );
        if (Input[x] != "A" || Input[x] != "B" || Input[x] != "C" || Input[x] != "B") {
            JOptionPane.showMessageDialog(null, "Please restrict input to 'A, B, C, or D'");
            System.out.println(Input[x]);
            System.exit(0);
        }
        else{ 
            System.out.println("This should print if A, B, C, or D is entered!");
        }
    }
}

}

alex2410
  • 10,904
  • 3
  • 25
  • 41
  • 2
    Compare `String` with help of `equals()` not (`==` or `!=`) !!! Read [here](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – alex2410 Mar 03 '14 at 07:30
  • 2
    Yea, what Alex said. And use Java naming convention. Variable names begin with lower case letters. `Input` -> `input` – Paul Samsotha Mar 03 '14 at 07:33

0 Answers0