View Single Post
  #2  
Old 04-22-2004, 05:23 PM
vee_ess's Avatar
vee_ess vee_ess is offline
Super Moderator
 
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
Send a message via ICQ to vee_ess Send a message via AIM to vee_ess Send a message via MSN to vee_ess Send a message via Yahoo to vee_ess
Default

Yeah... what language?

in java:
Code:
private static String RN(int number){ 
	int[] nums = { 1000, 500, 100, 50, 10, 5, 4, 1}; 
	String[] numerals = { "M", "D", "C", "L", "X", "V", "IV", "I"}; 
	boolean done = false; int x = 0; 
	while(done == false && x < 8) 
	{ 
		if(number >= nums[x]){ 
			done = true;
			return (numerals[x] + RN(number - nums[x])); 
		}
		x++;
	}
	return "";
} 
private static int number(String RN){
	int[] vals = new int[RN.length()];
	int total = 0;
	for(int x = 0; x < RN.length(); x++)
		vals[x] = val(RN.charAt(x));
	for(int x = 0; x < RN.length() - 1; x++){
		if(vals[x] < vals[x+1])
			total -= vals[x];
		else
			total += vals[x];
	}
	total += vals[RN.length() - 1];
	return total;	
}
private static int val(char c){ 
	int[] nums = { 1000, 500, 100, 50, 10, 5, 1}; 
	char[] numerals = { 'M', 'D', 'C', 'L', 'X', 'V', 'I'};
	for(int x = 0; x < 7; x++){ 
		if(c == numerals[x]) 
			return nums[x];  
	}
	return 0;
}
Reply With Quote