我正在尝试实现将DD/MM/YY输入转换为DD/MM/YYYY输入的程序的一部分。我使用了if语句来要求程序检查输入的数字是否为< 13,如果是,则将2000添加到输入数字 - 如果输入12,则输出2012。如果数量> 13 < 100,我已要求计划增加1900If语句的编译错误
我很新的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 */
}
}
'byear =(byear> 0)'你确定你知道这里发生了什么吗? –
基本上我想说只要输入年份超过0,就这样做。考虑一下,如果有人输入00(2000),这将是一个问题。也许如果我使用=> 0? –
多数民众赞成在Y2K问题一遍:P。但是回到原点。既然你正在检查,你不应该分配。基本上通过if。在第一行之前,例如12。下一步它是'true',然后'byear <13'没有任何意义。 –