Results 1 to 7 of 7
  1. #1
    rjagan's Avatar
    rjagan is offline Member
    Join Date
    Feb 2011
    Location
    Puducherry
    Posts
    53
    Rep Power
    0

    Default Printing Dec to Char Problem

    Hi Everyone,

    i have some problem to print the value.
    For Ex : if Dec 38 i will get &
    if Dec 2 i will get some unknown square boxes..

    Am using net beans..

    if i enter and print the values from Dec 32 to Dec 126 works finely. the decimal values 0 to 31 are not printing correctly.
    How can i print the equvalent char..

    am using this ascii table to convert dec to char : Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
    Help me friends..

    Thanks
    RJ
    ThanX
    Rj

  2. #2
    Join Date
    Sep 2011
    Location
    Mumbai, India
    Posts
    35
    Rep Power
    0

    Default Re: Printing Dec to Char Problem

    The system console on Windows and Linux is very limited on what characters it can display, i think it can display from 32 to 127, as you already said. So
    this is not your mistake, but what you can try is using JOptionPane to display i.e.
    JOptionPane.showMessageDialog(null, name_of_the_variable_which_you_want_to_display);
    Please import the javax.swing.JOptionPane; class at the top of your code.

  3. #3
    rjagan's Avatar
    rjagan is offline Member
    Join Date
    Feb 2011
    Location
    Puducherry
    Posts
    53
    Rep Power
    0

    Default Re: Printing Dec to Char Problem

    Hi Friend,

    I tried your idea in netbeans, JOptionpane is also display some square boxes not display the correct answers for those decimal values..

    Here is my code Friend :

    for(int i=0;i<5;i++)
    JOptionPane.showMessageDialog(null, (char)i);


    Help me, give some steps to print.

    Thanks
    RJ
    ThanX
    Rj

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: Printing Dec to Char Problem

    Quote Originally Posted by rjagan View Post
    Hi Everyone,

    i have some problem to print the value.
    For Ex : if Dec 38 i will get &
    if Dec 2 i will get some unknown square boxes..

    Am using net beans..

    if i enter and print the values from Dec 32 to Dec 126 works finely. the decimal values 0 to 31 are not printing correctly.
    What do you want it to print? The ASCII codes (or Unicode code points) for the range 0 ... 31 don't have a visible representation associated with it, so it prints the little box for you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Sep 2011
    Location
    Mumbai, India
    Posts
    35
    Rep Power
    0

    Default Re: Printing Dec to Char Problem

    I thought that the JOptionPane would work, but its not. Sorry.
    Yes there is a problem while printing those value below 32, i think a more experienced Java programmer can help.

  6. #6
    rjagan's Avatar
    rjagan is offline Member
    Join Date
    Feb 2011
    Location
    Puducherry
    Posts
    53
    Rep Power
    0

    Default Re: Printing Dec to Char Problem

    Hi JosAH,

    the range 0 ... 31 don't have a visible representation associated with it, so it prints the little box for you.
    then how to print those... is there any other encoding are avail to print netbeans..

    ThanX
    RJ
    ThanX
    Rj

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: Printing Dec to Char Problem

    Quote Originally Posted by rjagan View Post
    Hi JosAH,



    then how to print those... is there any other encoding are avail to print netbeans..

    ThanX
    RJ
    It's not a matter of encoding, in the Unicode or ASCII code there is no visible representation for the code points 0 ... 31. The little box indicates that fact.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Problem with scanning char
    By danthegreat in forum New To Java
    Replies: 4
    Last Post: 09-09-2011, 07:01 PM
  2. problem with reading a text file with special char
    By kishan.java in forum New To Java
    Replies: 1
    Last Post: 04-10-2011, 09:30 AM
  3. char problem.
    By santa in forum New To Java
    Replies: 5
    Last Post: 02-18-2011, 12:24 AM
  4. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  5. Problem with if statement - Char
    By KardKaper in forum New To Java
    Replies: 8
    Last Post: 12-22-2009, 01:14 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
  •