File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Roman Literals in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Roman Literals in Java" Watch "Roman Literals in Java" New topic
Author

Roman Literals in Java

VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
When displaying the time in a clock,if i want the numbers displayed as roman literals like I,II,III,IV..What should i do.is there any available API which takes the numbers and returns the roman literals corresponding to them?


SCJP 6.0
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Varun,
Welcome to JavaRanch!

There isn't an existing API to convert #s into Roman numerals, but it wouldn't be too hard for you to write one.

Mostly, there are mappings between numbers and symbols (5=V, 10=X, etc). Once you get one, you subtract that number and start over. Just watch for the exceptions (4,9,14,...)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you only need values for the numbers 1-12, I think it would be pretty easy to just make an array with 12 different strings for the 12 different values you need to convert.

Then you can just look up values from the array, yes?

One issue to beware of here is that the "first" elemnt of this array is element 0, which maps to "I", and the "second" is element 1, which maps to "II". So you will need to do something to fix this minor off-by-one error...


"I'm not back." - Bill Harding, Twister
VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
Thanks for the replies..Perhaps there is no place like javaranch where we can find answers so quickly..

Now, i have one more question. What if i want to use other languages like german and languages which have different character set like hindi etc.
How should i proceed..i know that java supports all character sets because of UNICODE support, but dont know how to print characters in other character sets .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Now you're asking a very different question. The question of using a German or other character set has nothing to do with Roman numerals. You can indeed use Java to show characters of any character set, as long as the required font is installed. E.g., something line Microsofts MS Arial Unicode font may be required to view Hindi, Chinese, Japanese or Korean characters. But be aware trhat many consoles can't handle Unicode, so System.out.println may not produce the results you expect.


Ping & DNS - my free Android networking tools app
VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
Yes, i did ask complete different question and thanks for the answer. But can you be more clear. I mean what API i have to use?. Is it just that i select the font installed in the system and use it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
You don't have to use any API - Java has all necessary capabilities built in. The important question is: where do you want Unicode characters to be displayed? Like I said, most consoles can't handle anything but ASCII, or maybe ISO-8859-1 if you're lucky, but not Hindi etc.

Web browsers can display those characters as long as you set the proper encoding (Content-Type should be "text/html; charset=utf-8") and an appropriate font is installed. Check this page to see which fonts you have.
[ July 06, 2006: Message edited by: Ulf Dittmer ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Aside from console output or a web application viewable from a browser, the other main option you may have is to build a GUI application using Swing/AWT or SWT. As a quick & simple option, you could do something like this:

Many more elaborate & complex applications are possible. If console output is good enough, that's easiest. If you want to print German on computers running in Germany, that will probably work fine. If the computer is in China, maybe not - it's probably set up differently. Otherwise you probably need to decide whether you want a web application or a GUI. Either option will require you to learn some additional technology.
VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
Thank you very much. I now understand better
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Roman Literals in Java