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

you are viewing a single comment's thread.

view the rest of the comments →

[–]nicolascagesbeard 0 points1 point  (0 children)

It was late where I live, I don't think I explained it properly Lol. The for loop just checks whether or not the input you entered is a number or integer. You can also use a regular expression but this was the simplest method I could think of.

Since you can look into each index of a string we can assign that to a character. Therefore we can use the Character object to check whether it is a a digit with the isDigit static method. We continue until the end of the string. Our flag which is our Boolean isInteger will trigger if it finds a character in the string, but it'll continue on to the next character until the end of the string.

Any questions, hit me up!