java万年历代码,能运行 100
展开全部
import
java.util.*;
public
class
Test4 {
public
static
void
main(String[] args){
Scanner in=
new
Scanner(System.
in
);
System.
out
.println(
"
请输入年份:
"
);
int
nian=in.nextInt();
System.
out
.println(
"
请输入月份
"
);
int
yue=in.nextInt();
int
sum=0;
for
(
int
year=1900;year<=(nian-1);year++){
if
(year%4==0&&year%100!=0||year%400==0){
sum=sum+366;
}
else
{
sum=sum+365;
}
}
for
(
int
month=1;month<=(yue-1);month++){
if
(month==2){
if
(nian%4==0&&nian%100!=0||nian%400==0){
sum+=29;
}
else
{
sum+=28;
}
}
else
{
if
(month==4||month==6||month==9||month==11){
sum+=30;
}
else
{
sum+=31;
}
}
}
sum=sum+1;
int
weekday=sum%7;
System.
out
.println(
"
日
\t
一
\t
二
\t
三
\t
四
\t
五
\t
六
"
);
for
(
int
i=1;i<=weekday;i++){
System.
out
.print(
"\t"
);
}
for
(
int
i=1;i<=30;i++){
if
(sum%7==6){
System.
out
.print(i+
"\n"
);
}
else
{
System.
out
.print(i+
"\t"
);
java.util.*;
public
class
Test4 {
public
static
void
main(String[] args){
Scanner in=
new
Scanner(System.
in
);
System.
out
.println(
"
请输入年份:
"
);
int
nian=in.nextInt();
System.
out
.println(
"
请输入月份
"
);
int
yue=in.nextInt();
int
sum=0;
for
(
int
year=1900;year<=(nian-1);year++){
if
(year%4==0&&year%100!=0||year%400==0){
sum=sum+366;
}
else
{
sum=sum+365;
}
}
for
(
int
month=1;month<=(yue-1);month++){
if
(month==2){
if
(nian%4==0&&nian%100!=0||nian%400==0){
sum+=29;
}
else
{
sum+=28;
}
}
else
{
if
(month==4||month==6||month==9||month==11){
sum+=30;
}
else
{
sum+=31;
}
}
}
sum=sum+1;
int
weekday=sum%7;
System.
out
.println(
"
日
\t
一
\t
二
\t
三
\t
四
\t
五
\t
六
"
);
for
(
int
i=1;i<=weekday;i++){
System.
out
.print(
"\t"
);
}
for
(
int
i=1;i<=30;i++){
if
(sum%7==6){
System.
out
.print(i+
"\n"
);
}
else
{
System.
out
.print(i+
"\t"
);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询