import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
try
{
Scanner san = new Scanner(System.in);
int n = san.nextInt();
if(n<0||n>=30)
{
throw new Exception();
}
System.out.println(fun(n));
}
catch(Exception e)
{
System.out.println("输入的数必须为大于0小于30的整数!");
}
}
public static int fun(int n)
{
if(n==1||n==2)
{
return 1;
}
else
{
return fun(n-1)+fun(n-2);
}
}
}
仅供参考哦
|