好吧,我正在嘗試編寫這段代碼,但我一直在收到這個愚蠢的錯誤。我不知道我做錯了什麼,所以也許你們的專家可以幫助我。Java錯誤缺失返回資料
import java.util.*;
public class School
{
Random randQuest = new Random();
int userAnswer;
public void createQuestion()
{
int range = 10; // range of numbers in question
int num1 = randQuest.nextInt(range);
int num2 = randQuest.nextInt(range);
userAnswer = num1 * num2;
System.out.printf("How much is %d times %d?\n",
num1, num2);
}
// prompt comment
public String promComm(boolean answer)
{
if (answer)
{
switch (randQuest.nextInt(1))
{
case 0:
return("Very Good!");
}
switch (randQuest.nextInt(1))
{
case 0:
return("No. Please try again.");
}
}
}
}
'return'不使用括號。 –
使用下面的任何正確答案解決問題後,請查閱[本文](http://www.informit.com/articles/article.aspx?p=1392524),其中Bob Martin指出應該從不編寫採用布爾參數的方法。這只是不好的做法。我知道這是一個無法回答的問題,但是你使用帶有布爾參數的方法是首先讓你陷入困境的原因!所以,希望你會發現這個技巧很有用。乾杯。 –