//gets the digit value and returns it as an int and if not valid, exists
public static int evalDigit(String in){
int result = -1;
switch (in){
case "0":
result = 0;
break;
case "1":
result = 1;
break;
case "2":
result = 2;
break;
case "3":
result = 3;
break;
case "4":
result = 4;
break;
case "5":
result = 5;
break;
case "6":
result = 6;
break;
case "7":
result = 7;
break;
case "8":
result = 8;
break;
case "9":
result = 9;
break;
default:
System.out.println("Invalid digit was entered, try again");
System.exit(2);
}
return result;
}
Actually the code they put doesn’t work at all — or rather it does, but not as they intended.
In this case they were actually comparing an address to a number (assuming String => char* in the case of C), which is perfectly valid, but that condition is likely never going to evaluate as true.
But even in Java, character literals are just numbers, so the comparison should be fine if that error is corrected
49
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Nov 13 '20
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!