Convert an roman integer in its decimal equivalent : http://tech-queries.blogspot.com/2010/03/convert-roman-integer-in-decimal.html
Convert IP Address From String To HexaDecimal : http://tech-queries.blogspot.com/2010/03/convert-ip-address-from-string-to-int.html
Convert IP Address From String To HexaDecimal : http://tech-queries.blogspot.com/2010/03/convert-ip-address-from-string-to-int.html
public static void convertToHexaDecimal(String s) {
StringTokenizer st = new StringTokenizer(s,".");
System.out.print("0x");
int i = Integer.parseInt(st.nextToken());
System.out.print(Integer.toHexString(i));
i = Integer.parseInt(st.nextToken());
System.out.print(Integer.toHexString(i));
i = Integer.parseInt(st.nextToken());
System.out.print(Integer.toHexString(i));
i = Integer.parseInt(st.nextToken());
System.out.print(Integer.toHexString(i));
}
The letters used in Roman numbers are:
- I = 1
- V = 5
- X = 10
- L = 50
- C = 100
- D = 500
- M = 1000
Convert Decimal number into roman number :
public class ConvertDecimalToRoman {
public static void main(String[] args) {
long num = 50;
// convert decimal number into roman number
StringBuilder roman = new StringBuilder("");
long count = 0;
if (num >= 1000) {
count = num / 1000;
while (count-- != 0)
roman.append("M");
num %= 1000;
}
if (num >= 500) {
count = num / 500;
while (count-- != 0)
roman.append("D");
num %= 500;
}
if (num >= 100) {
count = num / 100;
while (count-- != 0)
roman.append("L");
num %= 100;
}
if (num >= 50) {
count = num / 50;
while (count-- != 0)
roman.append("L");
num %= 50;
}
if (num >= 10) {
count = num / 10;
while (count-- != 0)
roman.append("X");
num %= 10;
}
if (num >= 5) {
count = num / 5;
while (count-- != 0)
roman.append("V");
num %= 5;
}
while (num != 0) {
roman.append("I");
num--;
}
System.out.println(roman);
}
}
No comments:
Post a Comment