请给出具体的代码
1条回答 默认 最新
- CSDN专家-sinJack 2021-11-18 11:25关注
import java.time.LocalDate; import java.util.Calendar; import java.util.Scanner; public class Test023 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.println("输入年份:"); int year = sc.nextInt(); System.out.println("输入月份:"); int month = sc.nextInt(); System.out.println("输入日期:"); int date = sc.nextInt(); Calendar c = Calendar.getInstance();// getInstance()返回当前默认语言环境的默认数值格式 c.set(year, month - 1, 1); int week = c.get(Calendar.DAY_OF_WEEK); String days = " "; switch (week) { case 0: days = "六"; break; case 1: days = "日"; break; case 2: days = "一"; break; case 3: days = "二"; break; case 4: days = "三"; break; case 5: days = "四"; break; case 6: days = "五"; break; } int max = c.getActualMaximum(Calendar.DATE); System.out.println("这个月的1号在星期" + days); System.out.println("这个月共有" + max + "天"); c.set(year, month - 1, date); int week1 = c.get(Calendar.DAY_OF_WEEK); String days1 = " "; switch (week1) { case 0: days1 = "六"; break; case 1: days1 = "日"; break; case 2: days1 = "一"; break; case 3: days1 = "二"; break; case 4: days1 = "三"; break; case 5: days1 = "四"; break; case 6: days1 = "五"; break; } System.out.println(year + "年" + month + "月" + date + "号在星期" + days1); System.out.println(year + "年" + month + "月的月历为:"); System.out.println("日\t一\t二\t三\t四\t五\t六"); for (int j = 1; j < week; j++) { System.out.print(" "); System.out.print("\t"); } int tag = week; for (int i = 1; i <= max; i++) { System.out.print(i); System.out.print("\t"); if (tag % 7 == 0) { System.out.println("\n"); } tag++; } System.out.println(); //以下运行条件java8 System.out.println("输入第一个日期的年月日,并用空格分开:"); LocalDate date1 = LocalDate.of(sc.nextInt(), sc.nextInt(), sc.nextInt()); System.out.println("输入第二个日期的年月日,并用空格分开:"); LocalDate date2 = LocalDate.of(sc.nextInt(), sc.nextInt(), sc.nextInt()); long day = Math.abs(date1.toEpochDay() - date2.toEpochDay());// Math.abs()--->返回int值的绝对值|x| //toEpochDay()在Module java.base--->Package java.time.chrono System.out.printf("这两个日期相差了%d天\n", day); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
- ¥200 求能开发抖音自动回复卡片的软件
- ¥15 关于freesurfer使用freeview可视化的问题
- ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
- ¥15 求SC-LIWC词典!
- ¥20 有关esp8266连接阿里云
- ¥15 C# 调用Bartender打印机打印
- ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
- ¥50 C#编程中使用printDocument类实现文字排版打印问题
- ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。