Results 1 to 11 of 11

Thread: Character Variable Increment

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink 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.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  4. #4

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink 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

  5. #5

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink 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.

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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

  8. #8
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  9. #9

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink 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?
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  10. #10
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  11. #11

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink 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.
    “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
  •  



Click Here to Expand Forum to Full Width