查看: 1271|回复: 5
|
请教教我如何做这题,要用什么code?
[复制链接]
|
|
请问有谁可以给我关于这题的code或告诉我该用什么code?
Roman numerals are used frequently to indicate dates, in particular the year (for example, MMVI represents the year 2006). There are two main differences between roman and arabic numerals.
- There is no symbol for zero in roman numerals;
- Numeral placement in the roman system can indicate either addition or subtraction.
Your task for this lab assignment is to convert a number ranging from 1 to 9999 to its roman numeral equivalent. Roman Numeral ConversionThe conversion is specified using the following cases. - I represents 1. Joining two I's together (i.e. II) represents 2, while III represents 3. However, IIII to represent 4 is forbidden because there is a shorter notation.
- V represents 5. Placing I before V (i.e. IV) will mean subtract I from V, i.e. 4. Note that we do not subtract more than one I from V, so IIV to represent 3 is invalid. Placing I after V (i.e. VI) will mean add I to V, i.e. 6. Likewise, VII and VIII represents 7 and 8. To represent 9 and 10, we do not use VIIII and VV respectively because there exist shorter notations.
- X represents 10. Following the rule above, IX is 9 while XI is 11.
- L represents 50 and works in much the same way as V. So XL is 40 while LX is 60. Additionally, XLI is 41, XLV is 45, XLIV is 44, XLVI is 46, XLIX is 49. Hopefully you get the picture...
- C represents 100.
- D represents 500.
- M represents 1000. M is the last character of the roman numeral system so to represent 9000, there is no choice but to use MMMMMMMMM.
The TaskWrite a program roman.java that requests a year from the user. Assuming that the executable is roman, a sample run of the program is shown below. User input is denoted in bold.Enter the year : 1Year 1 in roman numerals is I. | Enter the year : 2006Year 2006 in roman numerals is MMVI. | Enter the year : 1998Year 1998 in roman numerals is MCMXCVIII. | Enter the year : 9999Year 9999 in roman numerals is MMMMMMMMMCMXCIX. | Enter the year : 9888Year 9888 in roman numerals is MMMMMMMMMDCCCLXXXVIII. |
[ 本帖最后由 h@RT3r 于 2-2-2007 12:04 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 2-2-2007 11:47 AM
|
显示全部楼层
任何一种电脑语言都不是问题。
答案的方程式是用最大的值 1000 来除,比如说 2006 / 1000 = 2,就在 string variable 增 2 个 MM,余剩的数目再用比 1000 小的 500 来除,= 0,没有 D,... |
|
|
|
|
|
|
|
发表于 2-2-2007 03:58 PM
|
显示全部楼层
我用Java寫的架構讓你參考
- public Roman(int n) {
- int quotient;
- int mod;
- int i, j;
- final String roman = new String("MDCLXVI");
- final int[] array = {1000, 500, 100, 50, 10, 5, 1};
-
- System.out.print("Year " + n + " in roman numerals is ");
-
- quotient = n / array[0];
- mod = n % array[0];
- for ( i = 0; i < quotient; i++ ) {
- System.out.print(roman.charAt(0));
- }
-
- for ( j = 1; j < roman.length(); j++ ) {
- quotient = mod / array[j];
- mod = mod % array[j];
- // 判斷式自己寫
- }
- }
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 3-2-2007 08:16 PM
|
显示全部楼层
谢谢你门的帮忙,可以再帮我吗?
这题又如何做?这题是跟上题有关
Write a program clock.java that extends time.java such that the clock will begin ticking from the computed canonical time. The clock face should be updated after every one second has elasped.
Points to Ponder...
As we would like our clock to run for as long as possible, will your program eventually fail to function properly due to overflow error? How would you prevent it from happening? Remember: Overflow prevention is your responsiblity...
How would you expect your clock to perform in the long run? Would it be faster or slower? |
|
|
|
|
|
|
|
发表于 3-2-2007 09:01 PM
|
显示全部楼层
你到底是不会什么?只贴问题
感觉你是来这里问答案的 |
|
|
|
|
|
|
|
发表于 15-2-2007 06:49 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|