views:

515

answers:

5

"Auto increment" alphabet in java - is this possible? From A to Z without a 3rd party library?

+5  A: 

Yes, like this:

for (int i = 0; i < 26: i++)
{
    char upper = 'A' + i;
    char lower = 'a' + i;
    ...
}
Taylor Leese
+2  A: 
for (char c = 'a'; c <= 'z'; c++)
  //whatever
sdornan
The OP wants uppercase letters.
Asaph
+7  A: 
for (char c = 'A'; c <= 'Z'; c++) {
  ...
}
Laurence Gonsalves
Note that this will only do upper case. If you want lower case too you need two loops, or you can do two steps in each iteration and add the distance between 'A' ans 'a' to c each time.
CaptnCraig
I did not think this was possible :) thanks
Dacto
+5  A: 

you are looking for something like this:

    for( int i = 'a'; i < 'z'; i++ )
        System.out.println((char)i);//cast int to char
Michel Kogan
+5  A: 

yup ..possible

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

its possible with some typecasting also..

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

Hope this helps.. :D

Richie
omg haha i never even thought about this, i actually thought there was a magic function that did it lol. this is much better imo tho.
Dacto
glad to b of help... cheers!!
Richie