代码喝注释如下:
public static void main(String[] args) { System.out.print("Please input the month to check:") int month = new Scanner(System.in).nextInt()//月份//月份不在1~12的情哗磨况,提醒输入错误 if (month <= 0 || month > 12) { System.out.println("Error! month must be between 1 and 12!") }
//1-3月是春天
else if (month <= 3) { System.out.println("Month " + month + " is in Spring!") }
//4-6月是夏天
else if (month <= 6) { 雹氏System.out.println("Month " + 源芦散month + " is in Summer!") }
//7-9月是秋天
else if (month <= 9) { System.out.println("Month " + month + " is in Autumn!") }
//10-12月是冬天
else { System.out.println("Month " + month + " is in Winter!") } }
//E.javaimport java.util.Scanner
public class E {
public static void main(String[] args) {
int y,m,d,days,i,d1=0
System.out.printf("请输入滑旁液年,月,日启正:\n"信物)
Scanner in=new Scanner(System.in)
y=in.nextInt()
Scanner in1=new Scanner(System.in)
m=in1.nextInt()
Scanner in2=new Scanner(System.in)
d=in2.nextInt()
days=0
for(i=1i<mi++)
{ switch(i)
{ case 1: case 3: case 5: case 7: case 8: case 10: case 12:d1=31break
case 4: case 6:case 9: case 11:d1=30break
case 2:if(y%4==0&&y%100!=0||y%400==0) d=29else d1=28
}
days+=d1
}
System.out.printf("%d年%d月%d日是这一年的第%d天。\n",y,m,d,days+d)
}
}
import java.util.*/**
*
* 这里没有对输入非数字的数进行处理!
*/
public class Shell {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in)
int y = 0
int n = 0
System.out.println("请输入年份:")
y = sc.nextInt()
System.out.println("请输入月份:")
n = sc.nextInt()
switch (n) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(n + "月份有:31天")
break
//对于2月份需要判断是否为闰年
case 2:
if ((y % 4 == 0 && y % 100 != 0) 唯慧|| (y 猛裤% 400 == 0)) {
System.out.println(n + "月份有:29天")
break
} else {
System.out.println(n + "月份有:28天")
break
}
case 4:
case 6:
case 9:
case 11:
System.out.println(n + "月份有:30天")
break
default:
System.out.println("指知答请输入正确的年份和月份")
break
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)