0

I just have to make a method that checks if three integers are the same, have the user tell an object to execute this method, and then ask the user for another command. When I put 'c' (it's ONLY this case that does this, I have another case that is logically identical), it will do what it's supposed to but then it will try to take the next input and run it through as a parameter to the method that has already been executed, from what I understand.

 something=in.nextLine(); commands=something.charAt(0); do{ switch(commands){ //Blah blah blah other commands case 'c': boolean yes=object.allTheSame(in.nextInt(),in.nextInt(),in.nextInt()); System.out.println(yes); System.out.println("Please enter a command: "); something=in.nextLine(); break; } commands=something.charAt(0); }while(commands!='q'); 
1
  • You might be running into this problem. If that's the case, just put another in.nextLine(); on its own line before something=in.nextLine();. Commented Nov 1, 2013 at 18:35

2 Answers 2

1

The break you have in there breaks the switch statement and not the do-while loop.

(As your comparisons seem trivial, I think it's better form to use the tradition if-else.)

Sign up to request clarification or add additional context in comments.

Comments

0

I don't know what's in the "Blah blah blah other commands" part, but if the first character of something is not c, then commands will apparently never change. You might want to do this:

something=in.nextLine(); int pos = 0; commands=something.charAt(pos++); do{ switch(commands){ //Blah blah blah other commands case 'c': boolean yes=object.allTheSame(in.nextInt(),in.nextInt(),in.nextInt()); System.out.println(yes); System.out.println("Please enter a command: "); something=in.nextLine(); break; } commands=something.charAt(pos++); }while(commands!='q'); 

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.