-4

I am fairly new to Java programming and have been using a for loop in my program. I noticed whenever my program asks for user input, that whenever I press the enter key that is used as the next key for the second iteration of the loop. Is there a way to make this not occur?

2

1 Answer 1

1

Use while loop instead:

while(true){
          String input = JOptionPane.showInputDialog(null, "Please enter something.");//take inputs while have not encountered STOP
          if(input.equals("STOP")){
              System.exit(0);
          }
 }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.