【发布时间】:2012-11-07 17:45:42
【问题描述】:
我需要写一个把T画成圆圈的方法。
int s= T 的长度 int c= 要绘制的 T 的数量和每个 T 转动的度数
这是我的代码:
public static void r(int s,int c)
{
t.penDown();
t.forward(s/2);
t.left(90);
t.forward(s/4);
t.right(180);
t.forward((s/4)*2);
t.right(180);
t.forward(s/4);
t.left(90);
t.forward(s/2);
t.left(360/c);
}
int s = 行长 int c= 要绘制的 T 的数量(以及每次转动的度数)
画的是:一个4圈的T 这个方法是递归调用的,我找不到这个方法的任何停止条件 因为 int c 参数可以改变,因为它是转弯的角度,但它需要改变,因为那是我的停止参数。
有什么帮助吗?
【问题讨论】:
-
为什么不使用循环来调用 r() 一个固定的数字或次数?
标签: java recursion turtle-graphics