-
for culture说:
报时
private static void speakTime(){ Calendar cal = Calendar.getInstance(); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); if(hour == 0){ System.out.println(String.format("现在是零点%s分", minute)); } else if(minute == 0){ System.out.println(String.format("现在是%s点整", hour)); } else { System.out.println(String.format("现在是%s点%s分", hour, minute)); } } // 判断是否是闰年 private static void isLeapYear(){ Scanner scanner = new Scanner(System.in); System.out.print("请输入年份:"); try { int year = scanner.nextInt(); if((year%4 == 0 && year%100 != 0) || year%400 == 0){ System.out.println(year + "年是闰年"); } else { System.out.println(year + "年不是闰年"); } } catch (Exception e){ System.out.println("请输入整数年份"); } }
}
-
for culture说:
报时
/// public class ReportTime { /// /// 报时 /// public static void Report() { var now = DateTime.Now; var hour = now.Hour; var min = now.Minute; if (min == 0) { Console.WriteLine($"现在是{hour}点"); } else { Console.WriteLine($"现在是{hour}点{min}分"); } } }
}