Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

nextLine() question

800147Dec 10 2010 — edited Dec 12 2010
Hi everyone,
Scanner input = new Scanner();

for(i = 0; i < 5; i++){
			if(counter == 5){
					
                                        System.out.print("\nFirst class is full. Would you like to be put in economy class? (Yes or No): ");
					
					String s = input.nextLine();  // Why it doesn't wait for input from user?
					
					if(s == "yes")
						
                                                choice = 2;

					else if(s == "no")

						System.out.print("Next flight leaves in 3 hours");
					
					counter = 0;
				}
				
				while(array[counter] == false){
					array[counter] = true;
					displayBoardPass(1);
					counter = 0;
				}
				break;
				
			}
why when the program reaches the line
String s = input.nextLine(); 
it doesn't stop and wait for input from the user? It was supposed to wait for "yes" or "no" but instead it just continues executing the rest of the code.

Thanks in advance.

Edited by: blias on Dec 10, 2010 3:15 PM
This post has been answered by Kayaman on Dec 11 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2011
Added on Dec 10 2010
18 comments
1,011 views