万年历
以1900年1月1日为初始,这一天为星期一
//求出距离1900年1月1日一共多少天
Scanner s=new Scanner(System.in);
System.out.println("请输入年份");
int year=s.nextInt();
System.out.println("请输入月份");
int months=s.nextInt();
int count=0;
//算年
for(int i=1900;i<year;i++)
{
if((i%4==0&&i%100!=0)||i%400==0)
{
count+=366;
}
else
{
count+=365;
}
}
//算月
for(int i=1;i<13;i++)
{
if(i==2)
{
if((year%4==0&&year%100!=0)||year%400==0)
{
count+=28;
}
else
{
count+=29;
}
}
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) {
count+=31;
}
else
{
count+=30;
}
}
//blank为空格数
int blank=1+count%7;
if(blank==7) {
blank=0;
}
System.out.println(count);
System.out.print("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
for(int i=0;i<blank;i++)
{
System.out.print("\t");
}
int currentMonth;
if(months==2)
{
if((year%4==0&&year%100!=0)||year%400==0)
{
currentMonth=28;
}
else
{
currentMonth=29;
}
}
if(months==1||months==3||months==5||months==7||months==8||months==10||months==12) {
currentMonth=31;
}
else
{
currentMonth=30;
}
for(int i=1;i<=currentMonth;i++)
{
System.out.print(i+"\t");
if((i+blank)%7==0)
{
System.out.print("\n");
}
}
}
质数
//质数
// int count=0;
// for(int i=2;i<=100;i++) {
// boolean b=true;
// for(int j=2;j<i;j++) {
// if(i%j==0) {
// b=false;
// break;
// }
// }
// if(b) {
// count=count+i;
// }
// }
// System.out.println(count);
水仙花数
for(int i=100;i<999;i++) {
// int a=i%10;
// int b=i/10%10;
// int c=i/100;
// if(i==a*a*a+b*b*b+c*c*c) {
// System.out.println(i);
// }
// }