I was trying to get some code done for class:
public int getValue(char value) {
if (value == \'y\') return this.y;
else if (value == \'x\') return th
There is an implicit and natural conversion from int
to char
and vice-versa. Note that you thus have the usual arithmetic defined on char
m which comes very handy when you want, let's say, to iterate on the alphabet :
for (char c='a' ; c<='z' ; c++) { ... }
However, note that a char
is 2 bytes long whereas an int
is 4 bytes long, so casting an int
down to a char
may result in an integer overflow.