#Java Scanner
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
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())
should i make it a class member?
for the scanner
or a static field
alrighty, thanks for the advice
Also use lowercase for first letter, dont do GetUserInput() instead do getUserInput()
for more information about naming conventions:
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
This looks too much like C# syntax. I agree you should follow the conventions posted above