public class quickness {
public static void main(String []args) {
int x = f(48,12);
System.out.println(x);
}
public static int f(int y ,int t) {
    if (y%t==0)
return  y/t ;
}
}
这样的一段代码,为什么编译是这个quickness.java:9: missing return statement

解决方案 »

  1.   

    这个是语法错误还是逻辑错误啊,要是你用Eclipse写的,应该会提示出错,如果是用文本写的,又如果编译时没有报错,那它就是逻辑错误,呵呵!
      

  2.   

    你的代码当y%t!=0时就没有返回值了
    应改成
    public   static   int   f(int   y   ,int   t)   { 
            if   (y%t==0) 
               return     y/t   ;
            else
               return 0;
      

  3.   

    Java要求每个分支都能返回预期类型的值