import java.util.*;
//定义一个myjava类
public class myjava{
public static void main(String[] args)
{
Random r = new Random();
int mon = r.nextInt(12)+1;
int year =2000 + r.nextInt(10);
int day = r.nextInt(30);
System.out.println(year+"年"+mon+"月"+day+"日");
year temp = new year();
if(temp.isRunnis(year)==true)
System.out.println(year+"年是闰年");
else
System.out.println(year+"年不是闰年");
System.out.println(year+"年的第"+mon+"月有"+temp.getMonDay(year,mon)+"天");
}
}
//定义一个year的类
class year
{
int mon;
int year;
int day;
//定义一个isRunnis方法
public boolean isRunnis(int year)
{
boolean result = false;
if(year%4==0&&(year%100)!=0||year%400==0)
result=true;
return result;
}
//获取月数
public int getMonDay(int year,int mon)
{
boolean flag=new year().isRunnis(year);
int february = 28;
int result = 30;
if(flag == true)
february=29;
switch(mon)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
result = 31;break;
case 2:result = february;break;
}
return result;
}
//获取天数功能
public int getDay(int year,int mon,int day)
{
int mons[]={31,28,31,30,31,30,31,31,30,31,30,31};
boolean flag = new year().isRunnis(year);
int result=0;
int i=0;
if(flag==true)
mons[1]=29;
for(i=1;i<mon;i++)
result = result=result+mons[i];
return result+day;
}
}
相关文章
- 07-263.HTM编辑工具的推荐安装和汉化
- 07-26Arcgis Engine(ae)接口详解(3):featureClass的feature编辑和删除
- 07-26用Python的子进程模块包装Java程序的问题
- 07-26bash说话的Java子进程?
- 07-26vim编辑Dockerfile时语法高亮
- 07-26一次编辑~
- 07-26hive报错 java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default
- 07-26解决SharePoint 文档库itemadded eventhandler导致的上传完成后,编辑页面保持报错的问题,错误信息为“该文档已经被编辑过 the file has been modified by...”
- 07-26Sound Forge Pro音频编辑软件(Win版)
- 07-26问题-[Delphi]在对GRID设置单击为编辑时,其他GRID可以,但有一个GRID不行?