Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

how to print ascii characters on the screen

 
Bob Holland
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
freddie mercury
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
"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.
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please note that this is a topic from 2005. The poster is most likely not still waiting for an answer.
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic