资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

打印当月日历代码java,python打印日历代码

输入某年某月 打印出当月日历,要求日期和星期对应,用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();

}

}

}

}

输入年份月份,打印输出当月日历 用java

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class java {

public static void main(String[] args) throws IOException {

BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));

System.out.println("请输入年份:");

String s1=buf.readLine();

System.out.println("请输入月份: ");

String s2=buf.readLine();

int year=Integer.parseInt(s1);

int month=Integer.parseInt(s2);

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 13:

System.out.println("在"+year+"年的"+month+"月有:31天");

break;

case 4:

case 6:

case 9:

case 11:

System.out.println("在"+year+"年的"+month+"月有:30天");

break;

case 2:

if(year%4==0year%100!=0||year%400==0)

{

System.out.println("在"+year+"年的"+month+"月有:29天");

}

else

{

System.out.println("在"+year+"年的"+month+"月有:28天");

}

break;

}

}

}

Java编写程序,输入年份,输出本年度各月份日历

写了个简明的,

import java.util.Calendar;

import java.util.Scanner;

public class Test {

static public void main(String 参数[]){

Calendar c = Calendar.getInstance();

Scanner sc = new Scanner(System.in);

System.out.println("请输入年份:");

int year= sc.nextInt();

c.set(Calendar.YEAR, year);

c.set(Calendar.MONTH, Calendar.JANUARY);

c.set(Calendar.DAY_OF_MONTH, 1);

while(c.get(Calendar.YEAR)==year){

int wday=c.get(Calendar.DAY_OF_WEEK);

int mday=c.get(Calendar.DAY_OF_MONTH);

if(mday==1){

System.out.println("\n日\t一\t二\t三\t四\t五\t六\t第"+(c.get(Calendar.MONTH)+1)+"月");

System.out.println("---------------------------------------------------");

for(int i=0;iwday-1;i++) System.out.print(" \t");

}

System.out.print(mday+"\t");

if(wday==7) System.out.println();

c.add(Calendar.DAY_OF_YEAR, 1);

}

}

}

=======

请输入年份:

2012

日 一 二 三 四 五 六 第1月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

日 一 二 三 四 五 六 第2月

---------------------------------------------------

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29

日 一 二 三 四 五 六 第3月

---------------------------------------------------

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

日 一 二 三 四 五 六 第4月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30

日 一 二 三 四 五 六 第5月

---------------------------------------------------

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30 31

日 一 二 三 四 五 六 第6月

---------------------------------------------------

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

日 一 二 三 四 五 六 第7月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

日 一 二 三 四 五 六 第8月

---------------------------------------------------

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

日 一 二 三 四 五 六 第9月

---------------------------------------------------

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30

日 一 二 三 四 五 六 第10月

---------------------------------------------------

1 2 3 4 5 6

7 8 9 10 11 12 13

14 15 16 17 18 19 20

21 22 23 24 25 26 27

28 29 30 31

日 一 二 三 四 五 六 第11月

---------------------------------------------------

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30

日 一 二 三 四 五 六 第12月

---------------------------------------------------

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

用JAVA来实现日历输入年份和月份,打出本月的日历,求注释

public static int getDayCount(String dateTime) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

Calendar calendar = new GregorianCalendar();

try {

calendar.setTime(sdf.parse(dateTime));

} catch (ParseException e) {

e.printStackTrace();

}

int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

return day;

}

public static void main(String[] args) throws ParseException {

String mouth = "2015-02";

int day = getDayCount(mouth);

for(int i =1;iday+1;i++){

System.out.println(mouth+"-"+i);

}

}


分享题目:打印当月日历代码java,python打印日历代码
标题来源:http://cdkjz.cn/article/hdedgo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220