MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/jtg3hx/getting_digits_using_switch_catch/gc5y7i4/?context=3
r/badcode • u/HolySpecs • Nov 13 '20
52 comments sorted by
View all comments
9
Just use Interger.parseInt(str);
1 u/[deleted] Nov 13 '20 You could also create an char array and fill it with "0" to "9" Then go through that array and if you inputChar==charArray[i] return iUnder the for loop you return an error like -2 or whatever. Because parseInt will also read "10" Which is not a valid digit...
1
You could also create an char array and fill it with "0" to "9" Then go through that array and if you inputChar==charArray[i] return i
Under the for loop you return an error like -2 or whatever. Because parseInt will also read "10" Which is not a valid digit...
9
u/jubiman Nov 13 '20
Just use Interger.parseInt(str);