-1
我工作的一門功課,以創建一個程序,它有一個參數「n」和創建深度的領唱線,但它似乎並不奏效。我認爲可變範圍和功能存在問題。這是我第一次使用函數和遞歸,所以我仍然有點困惑。我有三個函數,一個繪製相對的左邊線,相對的右邊線和自動調用兩次的cantor函數,並調用兩個繪製函數。Cantor集遞歸問題。(作業)
public class Art
{
public static void drawLeftLine(double x0, double y0, double x1, double y1)
{
double x2 = (1/3.0)*(x1 - x0);
double x3 = x0;
double y2 = y0 - 0.1;
double y3 = y1 - 0.1;
StdDraw.line(x2, y2, x3, y3);
}
public static void drawRightLine(double x0, double y0, double x1, double y1)
{
double x2 = (2/3.0)*(x1 - x0);
double x3 = x1;
double y2 = y0 - 0.1;
double y3 = y1 - 0.1;
StdDraw.line(x2, y2, x3, y3);
}
public static void cantor(int n, double x0, double y0, double x1, double y1)
{
if (n == 0)
return;
drawLeftLine(x0, y0, x1, y1);
drawRightLine(x0, y0, x1, y1);
cantor(n-1, x0, y0, x1, y1); //left
cantor(n-1, x0, y0, x1, y1); //right
}
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]);
double x0 = 0;
double y0 = 0.9;
double x1 = 0.9;
double y1 = 0.9;
StdDraw.line(x0, y0, x1, y1);
cantor(n, x0, y0, x1, y1);
}
}
到目前爲止,您只說明瞭事實。你有什麼問題? –
請註明您收到的錯誤。 – mbeckish