本帖最后由 郭晓晨 于 2013-12-16 12:08 编辑
- public class Test {
-
- public static void main (String args []) {
- System.out.println (f(20));
- }
- public static long f(int j) {
- if (j==1 || j==2) {
- return 1;}
-
- int f1=1;
- int f2=2;
- int f=0;
- for (int i=1;i<=j-2;i++) {
- f=f1+f2;
- f1=f2;
- f2=f;
- return f;
- }
- }
- }
复制代码
这段代码报的错是
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
This method must return a result of type long
at test.Test.f(Test.java:8)
at test.Test.main(Test.java:6)
请教,问题出在哪里? |