"Auto increment" alphabet in Java?

Dacto picture Dacto · Jan 12, 2010 · Viewed 99.2k times · Source

"Auto increment" alphabet in Java - is this possible? From A to Z without a third-party library?

Answer

Richie picture Richie · Jan 12, 2010

Yes, you can do it like this:

for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) {
    System.out.println(alphabet);
}

It is also possible with typecasting:

for (int i = 65; i <= 90; i++) {
    System.out.println((char)i);
}