Results 1 to 9 of 9
  1. #1
    abi
    abi is offline Member
    Join Date
    Feb 2013
    Posts
    63
    Rep Power
    0

    Default Displaying ASCII Characters

    I am attempting to display ASCII characters from ! to ~ , in decimal index from 33 to 126, 10 in each line
    here is my progr

    Java Code:
    import java.util.*;
    import java.lang.*;
    
    public class ASCIICharacterSet
    {
      public static void main(String[] args)
      {
       int DeciIndex = 33;
       final int NUMBER_PER_LINE = 10;
       int count = 0;  
    
       while (count < NUMBER_PER_LINE )
        {
          for( ; DeciIndex == 126 ; ++DeciIndex)
          { 
            boolean goToNextCharc = true;
            
            if (goToNextCharc)
            {
             ++count;
            }
            if (count % NUMBER_PER_LINE == 0)     
           {
            System.out.print( (char)DeciIndex );
           }
           else
            {
             System.out.println( (char)DeciIndex + " " );
            }
         }
        }
    
      }
    }
    What am I doing wrong here?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Displaying ASCII Characters

    What is wrong with your current code? Does it compile without error? Does it run without exception? Is it misbehaving in some way?

  3. #3
    abi
    abi is offline Member
    Join Date
    Feb 2013
    Posts
    63
    Rep Power
    0

    Default Re: Displaying ASCII Characters

    My bad, it complies but there is no output..

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Displaying ASCII Characters

    Please translate what this for loop condition is supposed to do:

    Java Code:
    for( ; DeciIndex == 126 ; ++DeciIndex)
    {
    hint: I know what it's doing and why, and I want you to go through it and check each of the 3 sections to make sure you understand it too.

  5. #5
    abi
    abi is offline Member
    Join Date
    Feb 2013
    Posts
    63
    Rep Power
    0

    Default Re: Displaying ASCII Characters

    well,
    for a for loop
    for(initialization expression ; termination expression; increment/decrement statement)
    that is the general syntax right.
    So i did not put in an initialization expression as I already did so before the loop. Now the DeciIndex==126 expression is there because i want the loop to continue until the value of DeciIndex becomes 126 and finally the last expression adds one to the DeciIndex until it reaches 126.
    Am i Correct?

    Here is the more uptodate version of the code where I am getting all the ASCII characters but they are appearing vertically one after the other instead of 10 per line

    Java Code:
    // ASCII characters from unicode 33 to 126
    
    
    
    import java.util.*;
    import java.lang.*;
    
    public class ASCIICharacterSet
    {
      public static void main(String[] args)
      {
       int deciIndex;
       int count = 0; 
       final int NUMBER_PER_LINE = 10;
        
    
       while (count < NUMBER_PER_LINE)
        {
          for( deciIndex = 33; deciIndex < 127 ; deciIndex++)
          { 
            if( deciIndex <= 126 )
            {
              boolean goToNextCharc = true;
            
             if (goToNextCharc)
             {
              ++count;
             }
            
             if (count % NUMBER_PER_LINE == 0)     
             {
              System.out.print( (char)deciIndex );
             }
             else
             
              System.out.println( (char)deciIndex + " " );
             
            }
          }
        }
      }
    }
    Last edited by abi; 02-18-2013 at 07:15 AM.

  6. #6
    abi
    abi is offline Member
    Join Date
    Feb 2013
    Posts
    63
    Rep Power
    0

    Default Re: Displaying ASCII Characters

    Well, I have solved all my problems and got the program running. Thanks Fubarable

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Displaying ASCII Characters

    The middle part of the for loop is not a "termination" expression, it is a continuation expression. It must be true for the for loop to continue and the loop will terminate when its false. Is your expression ever true at the beginning, and if not, will the for loop ever stop? Answer: no and no.

  8. #8
    abi
    abi is offline Member
    Join Date
    Feb 2013
    Posts
    63
    Rep Power
    0

    Default Re: Displaying ASCII Characters

    Thank You

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Non-ASCII Characters
    By AJArmstron@aol.com in forum New To Java
    Replies: 6
    Last Post: 05-06-2010, 11:16 PM
  2. Randomly generate a range of Ascii Characters
    By Jamison5213 in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 03:48 AM
  3. [SOLVED] special characters (ASCII)
    By AlejandroPe in forum New To Java
    Replies: 8
    Last Post: 04-06-2009, 11:42 AM
  4. I need help with ascii characters
    By Grandon in forum Eclipse
    Replies: 17
    Last Post: 11-08-2008, 03:12 AM
  5. Printing ASCII values of characters
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-21-2008, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •