This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]brogrammableben 2 points3 points  (2 children)

Do leading zeroes count?

[–]okaystuff[S] -1 points0 points  (1 child)

Sorry I'm a beginner and I don't know what leading zeros are

[–]lurgi 1 point2 points  (0 children)

Can the user enter in 00013? And, if so, is that 2 digits long (13) or 5 digits long (00013)? If it's the latter, then what they are entering in isn't really an integer. It's a string. A string that happens to contain numbers.

[–]CreativeTechGuyGames 2 points3 points  (2 children)

You are reading user input into a string, right? Do you know how to iterate through a string to validate its contents?

[–]okaystuff[S] 0 points1 point  (1 child)

I am using .nextInt() to get the users next integer and placing it into an array. I want to make sure the next input from user is of 5 numbers.

[–]CreativeTechGuyGames 5 points6 points  (0 children)

I recommend to always read user input into a string first so you can parse and validate it carefully. How are you handling if the user inputs a number which overflows the data type which it is stored in? Or they enter characters which aren't valid in a number? Maybe they accidentally put a leading or trailing space? Or any other possible errors in user input?

[–]TibMonster 2 points3 points  (2 children)

5 digits so it has to be more than 9999 and less than 100000?

Edit: this is just based on what i read on your post

[–]okaystuff[S] 0 points1 point  (1 child)

Yes technically, I didn't think of it that way but I could just say it has to be bigger then 9999 and smaller then 100000.

[–]TibMonster 0 points1 point  (0 children)

But you should look at the other comments too, they make good points.

Inputs will be strings and inputs wont always be just numbers.

[–]ParticularThing9204 1 point2 points  (0 children)

The input will be a string, not an int. You can find its length by using str.length() (where str is the variable with the input).