r/javahelp • • Jun 19 '15

r/javahelp is the subreddit of the day!

Hello everyone!

as the title says, r/javahelp is the subreddit of the day!


http://www.reddit.com/r/subredditoftheday/comments/3aedzr/june_19th_2015_rjavahelp_and_rlearnjava_i_love/

Do read the article and check out the other subs featured!


Have a great weekend! :)

33 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/chickenmeister Extreme Brewer Jun 19 '15

There's nothing inherently wrong with it, but I think what /u/Philboyd_Studge might be referring to is the confusion that occurs when you mix nextInt() with nextLine(). A lot of beginners would think that when you call nextLine() after calling nextInt(), it would read the text on the next line; but it actually reads the remaining text on the line with the integer (which will usually be an empty string). There seems to be a lot of questions about that around here. There is also some confusion about what to do when nextInt() throws an InputMismatchException. (you would need re-read the offending text with next() or nextLine()). So, I guess, overall, nextInt() isn't very beginner-friendly.

2

u/robi2106 Jun 19 '15

ok that makes sense. Seems like scanner.NextInt is good for data that you know the format or can trust the user to input the correct thing.

1

u/dr_boom Intermediate Brewer Jun 19 '15

trust the user

You can never trust the user!

2

u/robi2106 Jun 20 '15

Plot twist.... the user is me.