导航:首页 > 编程语言 > 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打印日历相关的资料

热点内容
买安卓手机怎么在官网买 浏览:116
诗词入门PDF 浏览:355
毒app是什么单位 浏览:58
如何自己编译android系统 浏览:786
phpmysqlpdomysqli 浏览:802
php修改sql语句 浏览:714
android有道api 浏览:381
挠耳营水表用的什么app 浏览:49
战锤40kpdf 浏览:377
java判断字符串是汉字 浏览:464
2017初级教材pdf 浏览:453
松下空调压缩机品牌 浏览:819
python复选框 浏览:748
反诈中心app是什么时候出来的 浏览:588
魔兽世界需要什么服务器地址 浏览:191
啥是单片机休眠 浏览:106
什么音乐app最好 浏览:929
牙膏自制解压神器 浏览:329
卸载linuxwps 浏览:228
threadjavarunnable 浏览:360