我正在嘗試實現將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'沒有任何意義。 –