public class Fibby {
private static int fub (int n) {
if (n==1) {
return 1;
} else {
return n + fub(n-1);
}
}private static int iterFub(int n)
{
    if(n==0) throw new Exception("      "); // 这里需要抛出什么错误???  还有,什么时候用throws, 什么时候用throw??  //我抛出什么错误呢?? 有没有 方法,让Java自己识别是什么错误?
    for(int i=n-1; i>0; i--)
    {
        n+=i;
    }
    catch(Exception e)
    {
        System.err.print(e);
    }
    return n;
}public static void main (String[] args) {
//Insert statements here.
System.out.println("fub(0)=" + fub(1));
System.out.println("fub(2)=" + fub(2));
System.out.println("fub(3)=" + fub(3));
System.out.println("fub(4)=" + fub(4));
System.out.println("fub(5)=" + fub(5));
System.out.println("fub(6)=" + fub(6));System.out.println("iterFub(0)=" + iterFub(0));
System.out.println("iterFub(2)=" + iterFub(2));
System.out.println("iterFub(3)=" + iterFub(3));
System.out.println("iterFub(4)=" + iterFub(4));
System.out.println("iterFub(5)=" + iterFub(5));
System.out.println("iterFub(6)=" + iterFub(6));}}

解决方案 »

  1.   

    首先更正一点,那不叫错误,那叫异常,
    throw new Exception("      "); // 这里需要抛出什么错误???  还有,什么时候用throws, 什么时候用throw?? 
    这是你自己想让他抛出异常,是什么异常,你应该明白,否则就不要抛出来
      

  2.   

    if(n==0) throw new Exception("Illegal parameter. The parameter equals to zero."); // 这里需要抛出什么错误???  还有,什么时候用throws, 什么时候用throw?? 这里面的错误信息自己定义,能说明问题就好了。类扔异常用 throws程序扔异常 throw
      

  3.   

    if(n <= 0) throw new Exception("Illegal parameter. The parameter is lower than zero."); 该if条件,那段英文随便写,写中文都成。
      

  4.   

    new Exception("")里面填写的只是对异常的描述,去看看jdk里的Exception的构造方法就行.
    throw 是抛出一个自定义的异常.
    throws 是在某个方法上声明一个异常.
      

  5.   

    throw 你可以自己判定在什么位置抛出异常
    throws 你把抛出异常的功能交给了程序
      

  6.   

    if(n==0) throw new Exception("      "); // 这里需要抛出什么错误???  还有,什么时候用throws, 什么时候用throw?? throw new Exception(""),""里面的内容是对抛出异常的描述,if(n==0) throw new Exception("      "); 如果在控制台看到"  "里面的异常信息,那么你根据这些信息就能知道,在程序运行中,n=0throws是用在方法声明上的
    如:
    public void getName() throws Exception{
      ...
    }
    在这个方法体内会抛出异常,但是你不想在此方法内对其进行捕获(try-catch),那么就要在方法声明的时候把这个异常抛出,交给调用这个方法的其他方法处理(或抛出).