當前位置:編程學習大全網 - 編程軟體 - 求 java for循環 做 1 ,1,2,3, 5, 8 ,13 。。。的代碼

求 java for循環 做 1 ,1,2,3, 5, 8 ,13 。。。的代碼

我用的傳參的辦法 妳輸入的是可以循環幾位

class FeiBoNaXieShuLie

{

public static void main(String[] args)

{

System.out.println("Hello World!");

dingli z=new dingli();

z.add(args);

}

}

class dingli

{

void add(String v[])

{

if (v.length!=1)

{

System.out.println("請重新執行,能能輸入壹個數字:");

System.exit(0);

}

int a=Integer.parseInt(v[0]);

if (a>10)

{

System.out.println("請重新執行,能能輸入壹個小於10的數字:");

System.exit(0);

}

int b=0;

for (int c=a;c>=0 ;c-- )

{

System.out.print("菲波那契數列為"+feibo(c));

System.out.println("\t");

}

}

int feibo(int j)

{

int l;

if (j==0||j==1)

{

return j;

}

else

l=feibo(j-1)+feibo(j-2);

//System.out.print(l);

return l;

}

}

  • 上一篇:微信怎麽設置密碼?
  • 下一篇:機械手臂怎麽做
  • copyright 2024編程學習大全網