导航:首页 > 编程语言 > java打印日历

java打印日历

发布时间:2022-06-04 15:56:33

A. 输入某年某月 打印出当月日历,要求日期和星期对应,用java语言

import java.util.*;

public class riqi {
public static void main(String[] args) {
int totaldays = 0;
int dayofmonth = 0;
int twomonth;
Scanner input = new Scanner(System.in);
System.out.print("请输入年份:");
int year = input.nextInt(); // 输入年份
System.out.print("请输入月份:");
int month = input.nextInt(); // 输入月份
for (int i = 1900; i < year; i++) {
if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0)) {
totaldays = totaldays + 366;
} else {
totaldays = totaldays + 365;
}
}
for (int nomonth = 1; nomonth <= month; nomonth++) {
if (nomonth == 1 || nomonth == 3 || nomonth == 5 || nomonth == 7
|| nomonth == 8 || nomonth == 10 || nomonth == 12) {
dayofmonth = 31;
} else if (nomonth == 2) {
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
dayofmonth = 29;
} else {
dayofmonth = 28;
}
} else {
dayofmonth = 30;
}
if (nomonth < month) {
totaldays = totaldays + dayofmonth;
}
// System.out.println(totaldays);
}

System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期天");
int temp = (totaldays % 7);
// System.out.print(temp);
for (int p = 0; p < temp; p++) {
System.out.print("\t");

}
for (int w = 1; w <= dayofmonth; w++) {
System.out.print(w + "\t");
if ((totaldays + w) % 7 == 0) {
System.out.println();
}
}

}

}

B. 关于java中输出日历

Calendar c=Calendar.getInstance();//表示获取当前系统得时间对象;
c.set(Calendar.YEAR, year);//给对应的字段设置值,即设置年份,以下同理
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);

C. Java 打印两个月的日历


来个一年的,两个月并排。要是改成显示仅要两个月的,也不难。代码不长,不多解释了。

D. Java打印日历

这么无聊的要求、、、

E. 在Java中如何用calendar类输入年和月份打印当月的日历

51自学网有教程 详细的 网络下就好

阅读全文

与java打印日历相关的资料

热点内容
服务器的应用镜像是什么 浏览:151
命令行的使用方法 浏览:509
怎么让图片左右压缩 浏览:653
白鹿原pdf 浏览:431
人民币怎么算法 浏览:756
什么app可以听懂刺猬说话 浏览:598
安卓机内存小如何扩大 浏览:127
粉丝服务器怎么和安卓手机通信 浏览:400
初中数学竞赛pdf 浏览:570
linux自定义安装 浏览:190
fpic要在每个编译文件 浏览:868
编译原理广义推导的定义 浏览:911
怎么在已有的压缩文件里加密码 浏览:519
安卓手机怎么设置系统软件 浏览:768
php前端java后端 浏览:796
数据框转换为矩阵python 浏览:76
单片机程序反汇编 浏览:853
编程和实物不一样 浏览:880
天官赐福小说什么app可看 浏览:210
原车空调改压缩机 浏览:105