简单日历的制作 java
2017-12-16 15:21
302 查看
下面是本人学习的成果跟大家分享如何制作简单的日历,代码如下:
import java.util.Scanner;
public class A4_25{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入年份:");
int year=input.nextInt();
System.out.println("请输入月份:");
int month=input.nextInt();
int sum=0;
for(int beforeyear=1900;beforeyear<year;beforeyear++) {
if(beforeyear%4==0&&beforeyear%100!=0||beforeyear%400==0) {
sum+=366;
}else {
sum+=365;
}
}
for(int beforemonth=1;beforemonth<month;beforemonth++) {
if(beforemonth==2) {
if(year%4==0&&year%100!=0||year%400==0) {
sum+=29;
}else {
sum+=28;
}
}else if(beforemonth==4||beforemonth==6||beforemonth==9||beforemonth==11) {
sum+=30;
}else {
sum+=31;
}
}
sum+=1;
int wekday=sum%7;
System.out.println("日\t一\t二\t三\t四\t五\t六");
for(int i=0;i<wekday;i++) {
System.out.print("\t");
}
int monthday=0;
if(month==2) {
if(year%4==0&&year%100!=0||year%400==0) {
monthday=29;
}else {
monthday=28;
}
}else if(month==4||month==6||month==9||month==11) {
monthday=30;
}else {
monthday=31;
}
for(int i=1;i<=monthday;i++) {
if(sum%7==6) {
System.out.print(i+"\n");
}else {
System.out.print(i+"\t");
}
sum++;
}
}
}
import java.util.Scanner;
public class A4_25{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入年份:");
int year=input.nextInt();
System.out.println("请输入月份:");
int month=input.nextInt();
int sum=0;
for(int beforeyear=1900;beforeyear<year;beforeyear++) {
if(beforeyear%4==0&&beforeyear%100!=0||beforeyear%400==0) {
sum+=366;
}else {
sum+=365;
}
}
for(int beforemonth=1;beforemonth<month;beforemonth++) {
if(beforemonth==2) {
if(year%4==0&&year%100!=0||year%400==0) {
sum+=29;
}else {
sum+=28;
}
}else if(beforemonth==4||beforemonth==6||beforemonth==9||beforemonth==11) {
sum+=30;
}else {
sum+=31;
}
}
sum+=1;
int wekday=sum%7;
System.out.println("日\t一\t二\t三\t四\t五\t六");
for(int i=0;i<wekday;i++) {
System.out.print("\t");
}
int monthday=0;
if(month==2) {
if(year%4==0&&year%100!=0||year%400==0) {
monthday=29;
}else {
monthday=28;
}
}else if(month==4||month==6||month==9||month==11) {
monthday=30;
}else {
monthday=31;
}
for(int i=1;i<=monthday;i++) {
if(sum%7==6) {
System.out.print(i+"\n");
}else {
System.out.print(i+"\t");
}
sum++;
}
}
}
相关文章推荐
- java简单日历的制作代码
- Java简单日历制作
- java制作简单日历
- Java中简单日期类和日历类的小结
- Java中Date与Calendar小究以及应用Gregoriancalendar类实现简单的日历
- 简单日历的制作
- 基于java-applet的简单流程图绘制小工具的制作
- Java编写ArrayBasic制作一个简单的酒店管理系统
- java 实现简单的日历查询
- js+html制作简单日历的方法
- java制作简单的坦克大战
- java实现的一个简单日历
- 学习随笔——Java制作简单截图工具
- jquery制作一个简单的日历
- Java 日历的制作 心得 写给自己
- Java小程序之简单调度器(可制作小闹钟)
- 使用java制作简单验证码
- 制作简单日历
- java简单窗口日历程序,第一次写博文
- 学习随笔——Java制作简单猜数字小游戏