Can someone explain to me, how my method here in java that expects a int, but accepts '!' as an argument? further more, how can it interpet it as 33 when i debug it, but when i do System.out.println(Character.getNumericValue('!')); it prints -1?
here is the code guys:
public abstract class Stuff {
public static char getCharacterFromNumber(int number) throws InvalidCharException {
if(number>=20) {
if (number <= 45) {
switch (number) {
case 20:
return 'a';
case 21:
return 'b';
case 22:
return 'c';
case 23:
return 'd';
case 24:
return 'e';
case 25:
return 'f';
case 26:
return 'g';
case 27:
return 'h';
case 28:
return 'i';
case 29:
return 'j';
case 30:
return 'k';
case 31:
return 'l';
case 32:
return 'm';
case 33:
return 'n';
case 34:
return 'o';
case 35:
return 'p';
case 36:
return 'q';
case 37:
return 'r';
case 38:
return 's';
case 39:
return 't';
case 40:
return 'u';
case 41:
return 'v';
case 42:
return 'w';
case 43:
return 'x';
case 44:
return 'y';
case 45:
return 'z';
}
}
}
throw new InvalidCharException();
}
public static void main(String [] args){
try {
System.out.println(Stuff.getCharacterFromNumber('!'));
} catch (InvalidCharException e) {
e.printStackTrace();
}
System.out.println(Character.getNumericValue('!'));
}
}
i have searched but havent found anything similar to my problem, and if someone has a better idea for the title i'd appricate it :)