#Running a scanner String into an if statement and it's not working
20 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @south oasis! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
it shouldn't print out ANYTHING if i input exit
Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.
well i tried the equals method again, is it a syntax thing because i have no idea why it's still printing anything
your code currently executes the if, if the name is equal to exit
so I expect to see an S in the output
oh yeah let me try it on the original assignment again and see if it works
@brazen kite ok I have one more question, I need to get it to where it only prints out the flight listings on the left if you hit enter
yet i didn't hit anything and it reprinted the flight log
you cut of the important part. I need the code that follows after the if.
here's the whole method
sorry about I'm rushing a bit too much
Scanner#nextInt doesn't consume the new line character \n. If you call scanner.nextLine() in your if the statement consumes the new line character left by the previous operation. I recommend you don't mix Scanner#next methods and the Scanner#nextLine method. I'd read the entire line and parse to int to get the flight number
Alright, I don't have anymore problems, appreciate you helping me even though I'm kind of being stupid today
no worries that's why I am here