File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to print ascii characters on the screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

how to print ascii characters on the screen

Bob Holland

Joined: Dec 15, 2004
Posts: 7
hi there, i need to write a program which i can enter the first desired ascii character, and the last, and the program prints the list to the screen, but i dont know how to get started, do the characters have a numerical relation, please help Bob
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Yes, characters can be interchanged with numbers. ASCII is basically a mapping for doing just that. The character 'A' is 65, and 'B' is 66, for example.

If you write


you see the number 65, but if you cast the number to a "char", then you'll see the character 'A':

System.out.println((char) 65);

Note that Java doesn't actually use ASCII -- it uses Unicode, which is a (huge) superset. For your purposes, this might not matter.

[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Since characters are really represented as numbers under the hood, this means that you can "count" with them. So to print out every character in a given range, it sounds like a loop of some kind would be helpful. Does this give you any ideas where to start?

Once you have made a crack at working on this, post some of your code and we can help you refine it. Also, if you have any compiler errors, post those along with some indication of which line causes each error.

Keep Coding!


Java API Documentation
The Java Tutorial
freddie mercury

Joined: Aug 15, 2009
Posts: 1
hello, im new and i need help with something similar.[Deleted because what was posted was completely different. Please post your question again as a new thread.]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

"freddie mercury", please check your private messages for an important administrative matter.

Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
And, "Freddy Mercury" please do not ask questions unrelated to the original topic. So as to allow Bob Holland his thread back, I am afraid I feel obliged to delete most of your posting.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 1138

Bob Holland wrote: to the screen

I hope you are indeed referring to the command prompt.

Bob Holland wrote:do the characters have a numerical relation

yes, every character is represented by a numercial value
A = 65 and a= 97

you should use a char variable if you want the benefits of printing and iterating them.

I agree. Here's the better link:

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Please note that this is a topic from 2005. The poster is most likely not still waiting for an answer.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Jesper Young wrote:Please note that this is a topic from 2005. The poster is most likely not still waiting for an answer.
I hadn't noticed. Best to close the thread to avoid further confusion.
I agree. Here's the link:
subject: how to print ascii characters on the screen
It's not a secret anymore!