Convert numbers to roman numerals? [duplicate] - java

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do you find a roman numeral equivalent of an integer
I need to write a JSP function that will efficiently convert an integer (from 1 - 3000) to a roman numeral.

Start simple. Work out how you would convert the numbers 1 - 9 into Roman. Code and test. When it is working correctly, extend it to handle numbers up to 99. Again code and test. When it is working correctly, extend it to handle numbers up to 999. Code, test and extend up to 3,000.

Google has quite a few links to both algorithms and code:
http://www.google.com/webhp?hl=&sourceid=navclient-ff&rlz=1B3GGLL_enUS384US384&ie=UTF-8#hl=en&sugexp=gsis%2Ci18n%3Dtrue&cp=34&gs_id=3&xhr=t&q=decimal+to+roman+numeral+algorithm&pf=p&sclient=psy-ab&rlz=1B3GGLL_enUS384US384&site=webhp&source=hp&pbx=1&oq=decimal+to+roman+numeral+algorithm&aq=0&aqi=g1&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.&fp=d5bc1e92224c5138&biw=1003&bih=594

Related

How do I convert Text to HexaDecimal? [duplicate]

This question already has answers here:
How do you convert a byte array to a hexadecimal string, and vice versa?
(53 answers)
Closed 4 years ago.
I am looking for a way or multiple ways (Always good to know many ways) how to convert Text (String) to HexaDecimal like this http://codebeautify.org/string-hex-converter
Any help would be appreciated.
I've been looking for hours around different places and I have so far found no code that could potentionally do this for me.
All the ways that this could be done is accepted, I love learning about coding.
String to Hex:
Integer.decode(hexString);
Hex to String:
Integer.toHexString(integer);

solutions for randomly mix arraynumbers in android [duplicate]

This question already has an answer here:
Inbuilt Permutation Generator
(1 answer)
Closed 8 years ago.
hi im beginner in android and need a void that get numbers in array and give these numbers randomly mix.i try to make this something like these code but this is have bugs when it arrive to near of end.any body have solution for mix randomly numbers in array,like numbers between 1 to 20?
rand1=randomBox();
do {rand2=randomBox();
}while (rand1==rand2);
do {rand3=randomBox();
}while (rand1==rand3 || rand2==rand3 );
do {rand4=randomBox();
}while (rand1==rand4 || rand2==rand4 ||rand3==rand4);
.
.
.
Use Collections.shuffle(Arrays.asList(yourArray)) as explained in an other StackOverflow question: Inbuilt Permutation Generator

Outputting X^n without caret [duplicate]

This question already has answers here:
Subscript and Superscript a String in Android
(15 answers)
Closed 8 years ago.
I am writing a simple android app and I would like to set the text of a button to be X^n but I want it to look the same way as it would if you would write it on a piece of paper( for example 2⁶).
I know there are several unicode characters that does it for a small group of numbers but I am looking for a generel function (or any other way) that takes two integers and output the first by the power of the second. For example:
int X=2;
int n=6;
function(X , n) ==> 2⁶
I know a similar question was asked here before but its answers were not sufficient because I want to use variables' values and not actual numbers;
Thanks!
You can use html's <sup> tags for that:
button.setText(Html.fromHtml("X<sup>n</sup>"));

Weird Java extended ascii error [duplicate]

This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
I'm trying to do a comparison in Java with 2 strings containing a extended ASCII character.
boolean result = "éasdfasdf".substring(0,1).equals("é");
Can somebody explain why this results false? I think it has something to do with character encoding, but I can't figure out what exactly the problem is here...
Update: ideone.com does successfully run these 2 lines, so the problem is locally in my box. I think I found some more proof of that:
System.out.println("éb".charAt(1) == 'b');
Does also fails... Can it be the problem of 2 different character encodings?
Use
boolean result = "éasdfasdf".substring(0,1).equals("é")
And it will give expected result!The reason is simple - using '==' you compare objects by reference, not by value. So equals() solves this problem

Format a number with commas in two different fixed number of places [duplicate]

This question already has answers here:
DecimalFormat variable group size
(2 answers)
Closed 9 years ago.
An example will best explain what I want - lets say, I have a number like this 34236536465.57. I want to format it this way: 34,23,65,36,465.57. Any JDK classes or third party libraries I can use for this other than doing it manually please? I have tried with java.text.DecimalFormat("#,##,###.##"), but the commas are coming after 3 digits only whereas I want the commas to come first after 3 digits and then after 2 digits onwards.
com.ibm.icu.text.DecimalFormat class of ICU4J library can exactly do the same thing. And we can use the same pattern "#,##,###.##" as it is used in java.text.DecimalFormat to format the way exactly I wanted.

Categories