public int divide(int a,int b)
  {
  try{
  return (a/b);
  }catch(Exception e){
  e.printStackTrace();
  }
  }
有错误,总是显示此方法必须返回int类型的结果,可我已经返回了啊,???

解决方案 »

  1.   

    哦,刚没看完整
    public int divide(int a,int b)
      {
    try{
    return (a/b);
    }catch(Exception e){
    e.printStackTrace();
    }
    return 0//  这样应该没问题了,方法内应该显式指定返回值
    }
      

  2.   

    public int divide(int a,int b)
      {
    int temp = -1;
    try{
    temp = (a/b);
    }catch(Exception e){
    e.printStackTrace();
    }
    return temp;
      }
      

  3.   


    public int divide(int a,int b){
    try{
    return (a/b);
    }
    catch(Exception e){
    e.printStackTrace();
    return -1;
    }
    }
    这样就可以了哈