r/badcode • • Nov 13 '20

java Getting Digits using Switch Catch

Post image
881 Upvotes

52 comments sorted by

View all comments

3

u/hhellloo Nov 13 '20

I think this is better.

public static int evalDigit(string x)
{
 int result = Convert.ToInt32(x);
 if(result > 9 || result < 0)
 {
   result = -1;
 }
return result;
}

Edit: Oh, it is in Java, I thought it was c#

2

u/MsRandom1 Nov 13 '20

Just replace Convert.ToInt32 with Integer.parseInt for it to work in java.

2

u/NinjoMCS Nov 13 '20

And an uppercase String