#Java Scanner

1 messages · Page 1 of 1 (latest)

hexed yoke
#

I seem to be getting some sort of scanner error with this code. Am i doing something wrong here?

silver agateBOT
#

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

silver agateBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

hexed yoke
#

this is the error incase it helps

plucky minnow
#

u closed the scanner

#

never do that, that's wrong

#

once closed, u closed System.in itself and hence can never read from it again anymore

#

also, don't recreate scanners each time

#

create one single scanner and then reuse it through ur program

#

and finally, don't use nextInt

#

ull run into issues with it

#

instead, use
Integer.parseInt(scanner.nextLine())

hexed yoke
#

for the scanner

plucky minnow
#

or a static field

hexed yoke
#

alrighty, thanks for the advice

lunar lichen
#

Also use lowercase for first letter, dont do GetUserInput() instead do getUserInput()

solid gale
#

for more information about naming conventions:

silver agateBOT
#

The naming convention in Java is as follows:

Classes:
PascalCase. Example: GoldMiner, FoodDestroyer, DispenserBuilder

Methods / Fields / Variables:
camelCase. Example: foodAmount, integerValue, goodBoyAsADog

Packages:
All lowercase. Preferably the domain name backwards. Example: "google.com" ==> com.google, "ialistannen.me" ==> me.ialistannen
Followed by the project name. Example: Project "Builder" ==> com.google.builder

Constants/Enum entries:
UPPER_SNAKE_CASE. Where words are separated by underscores. Example: RED_DOG, I_AM_THE_BEST, CONQUER_WORLD

chrome owl
#

This looks too much like C# syntax. I agree you should follow the conventions posted above