aspose file tools*
The moose likes Beginning Java and the fly likes printing letters through for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "printing letters through for loop" Watch "printing letters through for loop" New topic
Author

printing letters through for loop

Paul Chamsay
Ranch Hand

Joined: Feb 06, 2009
Posts: 36
Hi,

I'm having a problem printing letters using a for loop..

I have this code:



The problem is what if I want to print out all the letters to Z? Obviously, putting all letters inside the letter array isn't really the best idea so I was wondering if something similar to this is possible:



I'm getting invalid unicode escape error on that code .. Thanks!
sandeep raj
Greenhorn

Joined: Mar 06, 2009
Posts: 10
if you are looking for a technique to print out the letters then you could probably do this as well


I believe you are getting the invalid unicode error cause at compile time the compiler is looking for 4 digits after \u and since you only 3 it gives the error
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Actually, your first code snippet has a bug. Line 4 should probably read:



I think Unicode escapes need to be two characters (i.e., \uNN) or four characters (\uNNNN). In any case, your second snippet won't work the way you think it will. You'll just print out whatever the Unicode character is, plus the number, six times. The plus just concatenates them in the output.

To get from A to Z, try this:



John.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369

Remember the definition of a character constant..

A character written between single quotes representing an "integer value" equal to the numerical value of the character in the machine's character set(Unicode,ASCII etc.)

So, if you try to print the integer equivalent of any character(i.e whatever unicode uses to represents a symbol), as a character, you will get a character constant.

For e.g: Integer equivalent of A,B and C in Unicode are 65,66 and 67. So, the following



will print A,B and C.

Using this idea you can print any character in the Unicode character set.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
Paul Chamsay
Ranch Hand

Joined: Feb 06, 2009
Posts: 36
Ah, thanks for the explanation guys, appreciate it
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
You can convert between char and int values, like this:
Paul Chamsay
Ranch Hand

Joined: Feb 06, 2009
Posts: 36
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing letters through for loop
 
Similar Threads
please help with simple problem
Binary search tree
HashMap and Vector
operator cannot be applied to ints.
Adding a usedChar array in my program