-3

如果计数小于 1,该方法应返回一个空字符串。我已经开始,但无法完成必须添加点数的最后一部分。

我的代码:

public String numOfDots (int count) {
    if(count < 1) 
        return " ";

    int numOfDots = 0;
    for(int i = 0; i < count; )

我需要从这里做什么?

4

2 回答 2

2
public String numOfDots(int count)
{
    StringBuilder retrStr = new StringBuilder();
    for (; count > 0; count--)
        retrStr.append("*");
    return retrStr.toString();
}

应该做的伎俩。

于 2013-04-29T23:08:36.493 回答
0

在 Clojure 中(嘿,问题只是标记算法):

(defn numOfDots [count]
  (clojure.string/join "" (repeat count "."))
)

输出(自己试试):

(numOfDots 10)
..........
于 2013-04-29T23:09:26.897 回答