ZKX's LAB

打印某年某月有多少天.

2021-04-09知识2

输入某年某月 打印出当月日历,要求日期和星期对应,用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;i+){if(((i%4=0)&(i%100。0))|(i%400=0)){totaldays=totaldays+366;} else {totaldays=totaldays+365;}}for(int nomonth=1;nomonth;nomonth+){if(nomonth=1|nomonth=3|nomonth=5|nomonth=7nomonth=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){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;p+){System.out.print(\"\\t\");}for(int w=1;w;w+){System.out.print(w+\"\\t\");if((totaldays+w)%7=0){System。.

java编写某年某月有多少天 借flyingFish211 的代码,把switch给你添上。不过flyingFish211的回复是很正确的,多学些类库很有用,使用类库中已存的方法,比自己写要省事,高效。import java.util。.

打印某年某月有几天?(Pascal) program ex1(input,output);vary,m:integer;beginreadln(y,m);case m of1,3,5,7,8,10,12:writeln('31');4,6,9,11:writeln('30');elseif(y mod 400=0)or(y mod 4=0)and(y mod 100<;>;0)then writeln('29')else writeln(28');end;end.

#打印某年某月有多少天

随机阅读

qrcode
访问手机版