aspose file tools*
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
Author

how to print ascii characters on the screen

Bob Holland
Greenhorn

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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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

System.out.println(65)

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!

Layne


Java API Documentation
The Java Tutorial
freddie mercury
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

"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] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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: 928

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
eg:
A = 65 and a= 97

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


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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: http://aspose.com/file-tools
 
subject: how to print ascii characters on the screen