我有一個任務,我正在爲我的班級做。我必須寫信要求一年,然後是月份的前三個字母的輸入。它將輸出以下聲明「2000年2月有29天」,從我所要求的項目中得到。它應該是區分大小寫的。不知道該怎麼做。任何人都可以將我指向正確的方向嗎?這也看起來不錯或我是馬虎。程序輸入必須區分大小寫
package test.project;
import java.util.Scanner;
/**
*
* @author XXXXXXX
*/
public class TESTPROJECT {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
System.out.print("Enter month (first three letters with the first letter in upper case): ");
String month = input.next();
//months
if (month.equals("Jan")){
System.out.print("Jan " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Feb")){
System.out.print("Feb " + year);
//LEAP YEAR FORMULA
if (year%4==0&&(year%100!=0||year%400==0))
{System.out.print(" has 29 days.");
if (year%4!=0&&(year%100==0||year%400!=0))
{System.out.print(" has 28 days.");}}
}
if (month.equals("Mar")){
System.out.print("Mar " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Apr")){
System.out.print("Apr " + year);
System.out.print(" has 30 days.");
}
if (month.equals("May")){
System.out.print("May " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Jun")){
System.out.print("Jun " + year);
System.out.print(" has 30 days.");
}
if (month.equals("Jul")){
System.out.print("Jul " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Aug")){
System.out.print("August " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Sep")){
System.out.print("Sep " + year);
System.out.print(" has 30 days.");
}
if (month.equals("Oct")){
System.out.print("Oct " + year);
System.out.print(" has 31 days.");
}
if (month.equals("Nov")){
System.out.print("Nov " + year);
System.out.print(" has 30 days.");
}
if (month.equals("Dec")){
System.out.print("Dec " + year);
System.out.print(" has 31 days.");
}
}
}
您的文章**是**區分大小寫。不確定你在問什麼。 –
要查看您的代碼是否正確,請先自己測試一下。如果它工作,很好,但也許繼續測試它。如果你的當前輸出與你想要的輸出不匹配,並且你不知道爲什麼,那麼是時候開始調試了。如果你不確定如何去做這件事,那麼請看看:[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-程式/)。 –
當我測試它。它仍然輸出,即使我輸入jan而不是1月。我正在嘗試查看是否缺少某些東西。 **等待!有用。對不起!** –