|
-
Sep 8th, 2006, 11:21 PM
#1
Thread Starter
PowerPoster
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.
-
Sep 9th, 2006, 12:03 PM
#2
Re: Character Variable Increment
Have you tried using the increment operator?
If that doesn't work, you can just cast, add, and cast back.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2006, 02:55 PM
#3
Re: Character Variable Increment
Code:
public static void main ( String args[] )
{
for(char i='a';i<='z';i++){
System.out.println(i);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 10th, 2006, 10:56 PM
#4
Thread Starter
PowerPoster
Re: Character Variable Increment
 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
-
Sep 10th, 2006, 11:03 PM
#5
Thread Starter
PowerPoster
Re: Character Variable Increment
 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.
-
Sep 11th, 2006, 06:38 AM
#6
Re: Character Variable Increment
What version of Java do you use?
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 11th, 2006, 03:00 PM
#7
Frenzied Member
Re: Character Variable Increment
 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
-
Sep 11th, 2006, 08:05 PM
#8
Re: Character Variable Increment
 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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 11th, 2006, 11:11 PM
#9
Thread Starter
PowerPoster
Re: Character Variable Increment
 Originally Posted by ComputerJy
What version of Java do you use?
I used JDK 1.4
Something wrong with it?
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
Sep 12th, 2006, 07:50 AM
#10
Re: Character Variable Increment
 Originally Posted by eranga262154
I used JDK 1.4
Something wrong with it?
The code above should work on 1.4
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 12th, 2006, 10:11 PM
#11
Thread Starter
PowerPoster
Re: Character Variable Increment
 Originally Posted by ComputerJy
The code above should work on 1.4
Ya, exactly,
I test your code and it is fine. Thanks.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|