r/badcode • • Nov 13 '20

java Getting Digits using Switch Catch

Post image
881 Upvotes

52 comments sorted by

View all comments

9

u/jubiman Nov 13 '20

Just use Interger.parseInt(str);

3

u/HolySpecs Nov 13 '20 edited Nov 13 '20

I wanted to do that but the normal inputs for the program were like:

+99
9
-98
&4
&4+89 (this line is wrong)

so if I did use Integer.parseInt(str) then I would get errors if, for example:

9+9

was entered

1

u/CollieOop Nov 13 '20

So instead you made a function that will call System.exit(2) on those inputs being entered instead of throwing an exception?