#Else if issue

1 messages · Page 1 of 1 (latest)

stone dawn
#

I am working on a eclipse project for a class i'm taking part in and for some reason this one else if stating keeps giving me the error message "Exception in thread "main" java.lang.Error: Unresolved compilation problem: Syntax error on token "else", delete this token". I do not know why I keep getting this error and was wondering what to do. Ive attached a picture of the code for context.

graceful dawnBOT
#

<@&987246399047479336> please have a look, thanks.

left mortar
#

there are several issues

#

so first line 71

#

it closes the else if with a ;

#

remove that

#

then you shouldnt really use Scanner#next()

#

and never compare strings with ==

#

but instead use .equals method

#

although a switch statement might make more sense here

stable sun
left mortar
#

just dont

#

thats bad advice for a beginner, because they dont understand what it really does

stone dawn
#

The semicolons were a mistake and removing them fixed my code and my teacher is making us use the Scanner class for all of our projects this year.

stable sun
#

You right. Sorry I butted in!

left mortar
#

but you should really prefer to use nextLine() when reading input

#

even if you read a single character, integer or whatever

#

do the conversion after reading

#

(usually)

stone dawn
#

ok thank you I will start to implement that instead from now one and I will also fix the ==s in my code.