public class EX02 {
public static int currentDay;
public static String result;
/**
* Constant.
* Every 3 days, feed worms.
*/
public static final int WORM_FEEDING_DAY = 3;
/**
* Constant.
* Every 5 days, bathe in sand.
*/
public static final int BATHING_DAY = 5;
/**
* Constant.
* Total number of days for which instructions are needed.
*/
public static final int NUMBER_OF_DAYS = 30;
/**
* Entry point of the program.
* @param args Arguments from command line.
*/
public static void main(String[] args) {
getInstructionForCurrentDay(currentDay);
// call and print getInstructionForCurrentDay inside a loop here
for (currentDay = 1; currentDay < NUMBER_OF_DAYS +1; currentDay++) {
currentDay = 30 - (NUMBER_OF_DAYS - currentDay);
System.out.println("DAY " + currentDay + result);
}
System.out.println("Can't fly back in time");
}
/**
* Return instruction for given day.
* @param currentDay number of day to print instructions for.
*/
public static String getInstructionForCurrentDay(int currentDay) {
if (currentDay % 3 == 0){
result = ":feed worms";
}
else if (currentDay % 5 == 0){
result = ":time to bath";
}
else if (currentDay % 5 == 0 && currentDay % 3 ==0 ){
result = ":glide";
}
else if (currentDay % 3 !=0 || currentDay % 5 != 0) {
result = ":give fruit and water";
}
return result;
}
}
問題是'getInstructionForCurrentDay(int currentDay)'在Main方法內不返回想要的值。我做錯了什麼?如果內部運算符沒有返回正確的值
'字符串str = getInstructionForCurrentDay(CURRENTDAY); ' – Satya
什麼是結果?它沒有在代碼示例中聲明... – fge
@fge:它是 - 代碼格式錯誤:( –