我正在尝试实现将 DD/MM/YY 输入转换为 DD/MM/YYYY 输入的程序的一部分。我使用 if 语句要求程序检查输入数字是否小于 13,如果是,则将 2000 添加到输入数字 - 如果输入 12,则给出 2012 的结果。如果数字 >13 且 <100,我已要求程序添加 1900。
我对 java 很陌生,并且遇到了两个我迄今为止无法克服的编译器错误(从 36 下降,哈哈)。编译器错误是“不是语句”。两者都引用带有 else 语句的行。代码如下(显然仍然是在制品,还不是完整的程序) -
import java.util.*;
public class FindDay4Birthdate
{
public static void main(String[] args)
{
String dayInput = "";
String monthInput = "";
String yearInput = "";
int bday;
int bmonth;
int byear;
String daysList[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
String monthList[] = {
"January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
};
Scanner sc = new Scanner(System. in );
sc.useDelimiter("[-/.\\s]");
System.out.print("Please enter your date of birth (dd/mm/yyyy) - ");
if (sc.hasNext())
{
dayInput = sc.next();
monthInput = sc.next();
yearInput = sc.next();
bday = Integer.parseInt(dayInput);
bmonth = Integer.parseInt(monthInput);
byear = Integer.parseInt(yearInput);
} // end if statement
if (byear = (byear > 0));
{
if (byear = (byear < 13))
{
byear = (byear + 2000);
}
else(byear = (byear > 13 && byear < 100));
{
byear = (byear + 1900);
}
} // end if statement
bmonth -= 1; //set month to correct array
String day = daysList[bday];
String month = monthList[bmonth];
int yearCount = (byear - 1901);
int daysInYear = 365;
int dayCount = (daysInYear * yearCount);
System.out.println("You were born on " + day + " " + bday + " " + month + " " + byear);
System.out.println(yearCount + " " + daysInYear + " " + dayCount); // test output only
/* Todo
*
*TASK 2 -
*Implement daysPerMonth - Feb set to 28 days
*Use count to determine correct day for birthdate
*
*TASK 3 -
*User input needs to allow char based months and 2 digit years need to be converted to 4 digit years
*Implement leap years */
}
}