我是 Java 新手,如果printMyProgress()
可以在不声明任何变量的情况下编写方法,我很感兴趣(String name = "Nat"; int time=0;).
public class Q7 {
String getMyName() {
String name = "Nat";
return name;
}
int getMyTimeSoFar() {
int time=0;
return time;
}
void printStudentProgress(String name, int time) {
String minute ="";
if (time==0||time>1)
minute = "minutes";
else minute = "minute";
print (name + " took " +time+ " "+ minute+" to reach Q7 in the Exam");
}
void printMyProgress() {
String name = "Nat";
int time=0;
printStudentProgress(name, time);
}
}