#Running a scanner String into an if statement and it's not working

20 messages · Page 1 of 1 (latest)

south oasis
#

So I was having issue with my assignment in class and I decided to do a test. I have tried using the .equals() method for the String and it still didn't work. If I input "exit" it should end but it's not doing that.

spring viperBOT
#

This post has been reserved for your question.

Hey @south oasis! Please use /close or the Close Post button 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.

south oasis
#

it shouldn't print out ANYTHING if i input exit

spring viperBOT
#

Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.

brazen kite
#

well as of right now you are printing a character.

#

if you want to exit, use return

south oasis
brazen kite
#

your code currently executes the if, if the name is equal to exit

#

so I expect to see an S in the output

south oasis
#

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

brazen kite
#

you cut of the important part. I need the code that follows after the if.

south oasis
#

here's the whole method

#

sorry about I'm rushing a bit too much

brazen kite
#

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

south oasis
brazen kite
#

no worries that's why I am here