I tried to compile the following code:
public static void main(String[] args){
for (char c = 'a'; c <='z'; c = c + 1) {
System.out.println(c);
}
}
When I try to compile, it throws:
Error:(5, 41) java: incompatible types: possible lossy conversion from int to char
The thing is, it does work if I write c = (char)(c + 1)
, c += 1
or c++
.
I checked and the compiler throws a similar error when I try char c = Character.MAX_VALUE + 1;
but I see no way that the value of 'c' can pass 'char' type maximum in the original function.