I just switched from C++ to Java. I’m trying to write a program that loops from 0 to some number less than 26. I want to get the letter of the alphabet that corresponds with that number.
For example, iteration 0 would be “A”. Iteration 2 would be “B”. 3 would be “C”.
In C++, I could just do ‘A’ + i and convert it back to a char. Is there a simple way of doing this in Java?
If you use the
charprimitive type you can do the same thing.Notice the second line where I had to cast back down to char (from int) as the addition operation is automatically widened to an int.