首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这两种方法有什么区别?JAVA

这两种方法有什么区别?JAVA
EN

Stack Overflow用户
提问于 2013-10-27 19:33:32
回答 3查看 139关注 0票数 1

我的教授给我提供了一些方法来填充一个罗马数字程序(以加法格式,例如4=IIII、9=VIIII等)。

我很难理解这两种方法之间的区别:

代码语言:javascript
复制
   **
   * This method prints, to the standard output and in purely additive
   * notation, the Roman numeral corresponding to a natural number.
   * If the input value is 0, nothing is printed. This
   * method must call the method romanDigitChar(). 
   * @param val   ?
   */

    public void printRomanNumeral(int val)
    {

    }

   **
   * This method returns the Roman numeral digit corresponding
   * to an integer value. You must use a nested-if statement.
   * This method cannot perform any arithmetic operations. 
   * @param val  ?
   * @return     ?
   */

    public char romanDigitChar(int val)

    {

    }

romanDigitChar是否应该一位一位地读取一个数字,并且一次只返回一个数字?如果是这样的话,我不明白printRomanNumeral将如何调用它。

我研究过其他的罗马数字程序,但我似乎找不到任何使用其他方法调用的方法,比如这个方法,我可以将它与之进行比较。

如有任何建议,敬请谅解!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-27 19:38:07

我假设romanDigitChar只返回一个精确匹配数字的一个字符,例如1、5、10、50、100等。printRomanNumeral会将已知值反复调用为数字,以便将它们转换为字符。我建议两个嵌套循环,一个用于具有递减值的特定字符的数量,另一个用于提取每个值。内环调用第二个方法。

我猜想他/她希望使用ASCII字符,尽管对于罗马数字有一些特殊的Unicode字符。

票数 5
EN

Stack Overflow用户

发布于 2013-10-27 19:41:42

首先,romanDigitchar返回一个字符(与作为输入的自然数相对应的罗马数字)。printRomanNumeral不返回任何东西,但应该打印罗马数字。

票数 1
EN

Stack Overflow用户

发布于 2013-10-27 19:43:27

Is romanDigitChar supposed to read a number digit by digit, and only return one digit at a time?是的,例如,如果您想打印两个罗马数字数字: IIII,VIIII。在void printRomanNumeral(int val)方法中,您需要执行以下操作:

代码语言:javascript
复制
public void printRomanNumeral(int val)
{
         System.out.println(romanDigitChar(4));
         System.out.println(romanDigitChar(9));          
}

但是在您的char romanDigitChar(int val)方法中,需要有一些算法来将自然数转换为罗马数字,比如:

代码语言:javascript
复制
    public char romanDigitChar(int val)
    {

        if(val == 4) {
          //Return a roman digit 4.
        }
        if(val == 9) {
          //Return a roman digit 9.
        }

      }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19622510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档