"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
2010-01-12 06:54:28
The OP wants uppercase letters.
Asaph
2010-01-12 06:57:04
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
2010-01-12 06:57:14
+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
2010-01-12 06:55:40
+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
2010-01-12 06:56:16