-1

我在代码的最后一部分找不到我的错误。最后一部分 ( printMyProgress()) 方法无法正常工作。

printMyProgress()调用调用的方法,将调用和方法printStudentProgress()返回的值作为参数传递。getMyName()getMyTimeSoFar()

public class first {
String getMyName() {
  String name = "Nat";
    return name;  
}
int getMyTimeSoFar() {
    int time=0;
    return time;
}

 void printStudentProgress(String name, int time) {
     String minute ="";
     if (time>1) 
     minute = "minutes";
     else minute= "minute";
     print (name + " took " +time+ " "+  minute+" to reach Q7 in the Exam");     
 }

   int printMyProgress() {
       String name = "Nat";
       int time=0;
       printStudentProgress(name, time);
       return printMyProgress();  
   }
}
4

2 回答 2

2

Because of this statement inside method printMyProgress:

return printMyProgress();

the method will recurse forever. If you do not depend upon the method returning a value, make the method return nothing (using void keyword instead of int) and remove the return statement:

void printMyProgress() {
   String name = "Nat";
   int time=0;
   printStudentProgress(name, time);
}
于 2013-10-30T22:40:20.877 回答
0

The last method is recursing (calling itself). As there is no code to break out of this recursion, the application will eventually (quickly) run out of memory and crash.

于 2013-10-30T22:40:52.950 回答