import acm.program.*;
public class Exercise1 extends Program{
public void run(){
int i;
for(i=1; i<=2; i++){
if(i==1){
int s = readInt("Give a number for the current day, 0:Sunday, 1:Monday, 2:Tuesday, 3:Wednesday, 4:Thursday, 5:Friday, 6:Saturday :");
String dayName1 = DayName(s);
int day1 = readInt("Give the number of the current day:");
int month1 = readInt("Give the number of the current month:");
int year1 = readInt("Give the current year:");
boolean flag = LeapYearCheck(year1);
int yearDays1 = YearDays(year1);
int monthDays1 = MonthDays(month1);
}
else{
int s = readInt("Give a number for your desired day, 0:Sunday, 1:Monday, 2:Tuesday, 3:Wednesday, 4:Thursday, 5:Friday, 6:Saturday :");
String dayName2 = DayName(s);
int day2 = readInt("Give the number of a day of your choice:");
int month2 = readInt("Give the number of a month of your choice:");
int year2 = readInt("Give your desired year:");
boolean flag = LeapYearCheck(year2);
int yearDays2 = YearDays(year2);
int monthDays2 = MonthDays(month2);
}
}
if(year1>=year2){
int sumC = yearDays1 + monthDays1 + day1;
int sumG = yearDays2 + monthDays2 + day2;
int sum;
if(sumG > sumC)
sum = sumG - sumC;
else if(sumC > sumG)
sum = sumC - sumG;
println("It has been " + sum + " Days since " + day2 + "/" + month2 + "/" + year2 + " " + dayName2);
}
else
println("This date has not come yet.");
}
public String DayName(int s){
switch (s){
case 0:return("Sunday");
case 1:return("Monday");
case 2:return("Tuesday");
case 3:return("Wednesday");
case 4:return("Thursday");
case 5:return("Friday");
case 6:return("Saturday");
}
}
private boolean LeapYearCheck(int Y){
boolean flag;
if(Y/4 == 0 && Y/100 != 0 || Y/400 == 0 && Y/100 !=0)
return flag = true;
else
return flag = false;
}
private int YearDays(int y){
if(flag == true)
return 366;
else
return 365;
}
private int MonthDays(int m){
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
return 31;
else if(m!=2)
return 30;
else if(flag==true)
return 29;
else
return 28;
}
}
每次我試圖編譯命令行上,我得到14個錯誤的所有類型的:**error: cannot find symbol
。例如:找不到符號在編譯Java代碼
Exercise1.java82: error: cannot find symbol else if(flag==true).
符號^
也是f
下方。
'flag'不'YearDays(int y)對聲明做'或'中MonthDays(INT米)'。它超出了範圍,因爲它僅在'run()'和'LeapYearCheck(int Y)'中定義。 – Gendarme