Reputation: 4547
I have a Java program that generates a text file with a word per each line in the file. I want to make the program automatically generate and write the number of each line in the file. This number can have different formats like :
1, 2, 3, ...
a, b, c, ..., z, aa, ab, ac,....
i, ii, iii, ...
Coding this is simple, except for generating those number formats. The first format(1, 2, 3, ...) is of course easy, but is there any java numbers library or logic that can generate consecutive Latin or Letters like the 2nd and 3rd ones i have mentioned above ?
Upvotes: 2
Views: 681
Reputation: 11
Each letter has a integer equivalent.
Using ASCII as an example
97 = 'a' in ASCII
char c = (char) 97; // is now 'a'
so staring with 97++ and casting to a char will give you the alphabet in order required
Upvotes: 0
Reputation: 340883
To generate the second form you need to translate a decimal number (base 10) to a number with base 26. Each "digit" is a character from a
to z
. This can be done by a sequence of x % 26
and x /= 26
operations until you reach 0
.
For Roman numbers check: How do you find a roman numeral equivalent of an integer.
Upvotes: 3
Reputation: 10369
You can find on the internet some functions already written to get Excel based numbers of columns:
http://soyouwillfindit.blogspot.com/2009/04/there-is-that-kind-of-odd-number-system.html
About Roman numbers, here you have :
http://www.roseindia.net/java/java-tips/45examples/misc/roman/roman.shtml
Upvotes: 0