|
You last visited: Today at 05:08
Advertisement
Help with Java Programming
Discussion on Help with Java Programming within the General Coding forum part of the Coders Den category.
07/10/2013, 08:29
|
#1
|
elite*gold: 0
Join Date: Jul 2013
Posts: 95
Received Thanks: 2
|
Help with Java Programming
this is what I need to do :
One of the principal stumbling blocks in the early development of mathematics was the notation used for numbers before the “Arabic” or “decimal” number system was introduced, since some of the older number systems were quite unsuited for arithmetic. As an example, the Roman system of numbers makes use of the symbols M (with value 1000), D (value 500), C (value 100), L (value 50), X (value 10), V (value 5), and I (value 1).
In the “old Roman” or “Classical” system a number is a sequence of M’s, D’s, C’s, L’s, X’s, V’s, and I’s in that order, the value of a number just being the sum of the values of the individual symbols.
Write a program that will convert a classical Roman numeral to a decimal number.
kinda lost help please
|
|
|
07/10/2013, 13:46
|
#2
|
elite*gold: 124
Join Date: Feb 2012
Posts: 302
Received Thanks: 135
|
Im sorry but this is the wrong section.
|
|
|
07/10/2013, 17:27
|
#3
|
elite*gold: 900
Join Date: Apr 2009
Posts: 14,981
Received Thanks: 11,403
|
.NET Languages -> General Coding
moved
|
|
|
07/11/2013, 17:55
|
#4
|
elite*gold: 112
Join Date: Mar 2008
Posts: 256
Received Thanks: 21
|
Easy, but maybe not the best solution:
I = userinput;
if(I>=5)
{
V = Math.round(I/5);
I=I%5;
}
else if(V>=2)
{
X=Math.round(V/2);
V=V%2;
}
didn't try it, just wrote it here quickly.
Sure, there are better solutions.
|
|
|
07/19/2013, 10:53
|
#5
|
elite*gold: 0
Join Date: Jun 2013
Posts: 294
Received Thanks: 38
|
int[] roman = {...};
int dec = 0;
for(int i = 0; i < input.length; i++)
{
dec+=roman[substring(input, i, i+1)];
}
Create an array => roman["V"] = 5; ...
|
|
|
07/28/2013, 21:49
|
#6
|
elite*gold: 135
Join Date: Oct 2007
Posts: 1,088
Received Thanks: 210
|
Quote:
Originally Posted by Aegir112
int[] roman = {...};
int dec = 0;
for(int i = 0; i < input.length; i++)
{
dec+=roman[substring(input, i, i+1)];
}
Create an array => roman["V"] = 5; ...
|
Not completly right if an lower roman char is infront of an higher one u would need subtract
|
|
|
07/29/2013, 17:45
|
#7
|
elite*gold: 0
Join Date: Jan 2013
Posts: 30
Received Thanks: 15
|
re
Code:
public static int convert(string nr)
{
if (nr == string.Empty) return 0;
if (nr.StartsWith("M")) return 1000 + convert(nr.Remove(0, 1));
if (nr.StartsWith("CM")) return 900 + convert(nr.Remove(0, 2));
if (nr.StartsWith("D")) return 500 + convert(nr.Remove(0, 1));
if (nr.StartsWith("CD")) return 400 + convert(nr.Remove(0, 2));
if (nr.StartsWith("C")) return 100 + convert(nr.Remove(0, 1));
if (nr.StartsWith("XC")) return 90 + convert(nr.Remove(0, 2));
if (nr.StartsWith("L")) return 50 + convert(nr.Remove(0, 1));
if (nr.StartsWith("XL")) return 40 + convert(nr.Remove(0, 2));
if (nr.StartsWith("X")) return 10 + convert(nr.Remove(0, 1));
if (nr.StartsWith("IX")) return 9 + convert(nr.Remove(0, 2));
if (nr.StartsWith("V")) return 5 + convert(nr.Remove(0, 1));
if (nr.StartsWith("IV")) return 4 + convert(nr.Remove(0, 2));
if (nr.StartsWith("I")) return 1 + convert(nr.Remove(0, 1));
throw new ArgumentOutOfRangeException("bad input or bad code");
}
~RGrand
|
|
|
 |
Similar Threads
|
HILFE - Gästebuch - VIDEOS EINBINDEN BBCODE (Java Programming)
01/22/2012 - Web Development - 2 Replies
Ich brauche Hilfe bei meinem Gästebuch.
Kann mir jmd die funktion geben um Videos ins Gästebuch einzubinden.?
Beispiel:
Kamioka - Hands Up vs. Hardstyle Mixtape'1 - YouTube
function InsertURL()
{
var url = GetSelectedText(document.posting.p_text);
|
INFIX TO POSTFIX JAVA PROGRAMMING[HELP]
01/13/2012 - General Coding - 2 Replies
Good Day Elitepvpers. Can some of you give me a source code of converting infix to postfix ? and also postfix to infix. I just badly need it. I'm still using search engines now. And also i need some helping hands here. I need a program with an input process.
Sample Program:
Input : (a+b)*c/(d+e)*f
Output: ab+c*de+f*/
Hope u can help me with these. Thank you !
|
Java Programming Help Again please :'(
10/06/2011 - General Coding - 1 Replies
How do i do this program???
Create an array that will Input a year (valid years are starting from 1900 onwards) then output the index number and the animal sign of the entered year. These are the sequence of the animal signs: RAT, OX, TIGER, RABBIT, DRAGON, SNAKE, HORSE, SHEEP, MONKEY, ROOSTER, DOG, PIG.
Sample output:
Enter a year: 1200
<<VALID INPUT STARTS AT 1900>>
Enter a year: 1984
|
Java Programming
10/11/2008 - CO2 Programming - 10 Replies
Hi guys, i am an experienced 2 year computer science HL java programmer :P just wondering where to start off to making programs for co? i wana make a new auto-clicker with timed clicks for intensify and a guard leveler :P
|
All times are GMT +2. The time now is 05:09.
|
|