Character Variable Increment
Hi....
Please consider the following lines.
char index = 'a';
System.out.println(index);
This will printout letter ‘a’. I want to display all the letters (i.e. from ‘a’ to ‘z’), can someone explain how to do this using any iteration. Only condition is variable index should be character type.
Re: Character Variable Increment
Have you tried using the increment operator?
If that doesn't work, you can just cast, add, and cast back.
Re: Character Variable Increment
Code:
public static void main ( String args[] )
{
for(char i='a';i<='z';i++){
System.out.println(i);
}
}
Re: Character Variable Increment
Quote:
Originally Posted by CornedBee
Have you tried using the increment operator?
If that doesn't work, you can just cast, add, and cast back.
Thanks a lot dear,
I forgot that. Let me tried
Re: Character Variable Increment
Quote:
Originally Posted by ComputerJy
Code:
public static void main ( String args[] )
{
for(char i='a';i<='z';i++){
System.out.println(i);
}
}
Thanks a lot, it's ok.
I'll try to do this before, but something wrong on it.
Re: Character Variable Increment
What version of Java do you use?
Re: Character Variable Increment
Quote:
Originally Posted by ComputerJy
Code:
public static void main ( String args[] )
{
for(char i='a';i<='z';i++){
System.out.println(i);
}
}
You beat me too it ;)
This piece of code is very useful in many different situations ;)
Re: Character Variable Increment
Quote:
Originally Posted by System_Error
You beat me too it ;)
This piece of code is very useful in many different situations ;)
Yeah, you are right.
y'know, the things that Java can do always amaze me
Re: Character Variable Increment
Quote:
Originally Posted by ComputerJy
What version of Java do you use?
I used JDK 1.4
Something wrong with it?
Re: Character Variable Increment
Quote:
Originally Posted by eranga262154
I used JDK 1.4
Something wrong with it?
The code above should work on 1.4
Re: Character Variable Increment
Quote:
Originally Posted by ComputerJy
The code above should work on 1.4
Ya, exactly,
I test your code and it is fine. Thanks.