aspose file tools*
The moose likes Java in General and the fly likes How to print ASCII values of all characters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to print ASCII values of all characters?" Watch "How to print ASCII values of all characters?" New topic
Author

How to print ASCII values of all characters?

Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Hello all,

I have one assignment to print ASCII values of all characters using java.
i.e.Console application.

Can anyone Please guide me in this regard?


With Regards,
Anu
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Loop through the characters in a FOR loop and print out the value of the char which is cast to int.

Try this.

I am pasting the answer below, but suggest you first try it based on the above explanation, without looking at the code below.

[deleted - Jim]
[ November 17, 2005: Message edited by: Jim Yingst ]

ASCII silly question, Get a silly ANSI.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Ahem. At this site we really prefer not to simply give people the answer. So I deleted it from the previous post.

Ashvini: some questions for you to consider:

What is the largest (and smallest) possible value of a char variable in Java?

What is the largest (and smallest) possible ASCII value?

If a char is a type of integer value, what's a way to convert from one type of number to another? For example, how could you convert a double to an int?


"I'm not back." - Bill Harding, Twister
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Originally posted by Jim Yingst:
Ahem. At this site we really prefer not to simply give people the answer. So I deleted it from the previous post.



Alright Jim. I was in double mind too, but decided to leave it to the asker the restraint of not looking at the answer. But if this is the preferred approach...
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Jim,
I really don't know answer for both the questions....I will write the code. Please guide me with the logic and the ASCII concept.



Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Help us understand where you are ...

Are you comfortable with making a one-class program, main() method and getting it running?

Are you comfortable with for loops, say incrementing an int from 0 to some limit?

Are you comfortable with the relationship between int and char?

Do you have a good book or reference to help with things like this? Thinking In Java is a good free online book.
[ November 21, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
James,
I am an intermediate programmer in java.
Yes, i am comfertable with single class and running it.
I am capable of doing complex loops
I know the convertion of ASCII code to String:


I know the convertion of integer to ASCII code (byte)


Anticipating some guidelines at the earliest....Thanks in advance
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Ashvini, do you find any lack of clarity in the algorithm I suggested above??
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Ash,

you wrote:
"Loop through the characters in a FOR loop and print out the value of the char which is cast to int."

But,
I am not understanding two concepts:
1) How to input characters,for which ASCII values has to be displayed ?
2) What should be the minimum and maximum limits for the loop?
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Originally posted by Ashvini Devi:
Ash,

But,
I am not understanding two concepts:
1) How to input characters,for which ASCII values has to be displayed ?
2) What should be the minimum and maximum limits for the loop?


That lies in Stans post. If u are able to answer both Stans Q, then u have the program. Thats a clue.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think we're homing in on what's missing. Google on 'ASCII character set' to find the range of numbers. Note that quite a few of them do special things when printed, eg tab or newline or ring the bell on the printer (your printer doesn't have a bell?) so it can be a little tricky to print a nice grid of all the characters. Consider a map or something to look up the descriptive names of these special characters.
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Hi,
I am trying to write the program.
I am asking user to strike a key on the keyboard. With respect to that, ASCII value has to be printed.
I am first converting the string to int and then int to ASCII value.

But:
my problem is:
1)I am getting exception as String "a" cano't be converted in to int.
2)how to convert string to Char?
3)How to findout, whether the user input is a number or a character ?

Please help! i am posting my code here.


Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Otherwise,
as Ash said, i don't know how to loop through all the characters to print at a stretch. i want the ASCII values from 32 to 127... (need not be all characters)

Thanks in advance.

:roll:
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Can you write a loop with a variable which starts at 0 and ends at 10?

Can you write a loop with a variable which starts at 32 and ends at 127?
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
YEs.
My program is working now.
Thanks to all
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Ashvini Devi wrote:Hello all,

I have one assignment to print ASCII values of all characters using java.
i.e.Console application.

Can anyone Please guide me in this regard?


-----------------------------------------------------------------------------------------------------
hi Ashvini

[Deleted]


Creativity is nothing but Breaking Rules
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Santosh,

Do you really think the OP is waiting these many years for the solution? (..and if you have read the OP's last post, she did say she got it).

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18977
    
  40


Also ... it is nicer to help someone solve their homework assigment instead of just giving them the solution. (You can't learn if you just get the solution).... I deleted the solution, just in case, another student from the same instructor needs to do the same assigment.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to print ASCII values of all characters?