JAVA
我跟你一样,刚学java一个月,感觉还不错.
加油!!!
下面是我自己刚学完循环之后写的一个简单的程序,看下啊,给点建议哦...
import java.util.*;
public class XiaoHong
{
public static void main(String[] args)
{
System.out.println("*****************欢迎使用小红的万年历****************");
Scanner input = new Scanner(System.in);
// 扫描器,从键盘接收输入
int year;
int month;
String answer = "y";
while (answer.equals("y"))
{
boolean isRn = false;
System.out.println("请输入年份:");
year = input.nextInt();
System.out.println("请输入月份:");
month = input.nextInt();
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
System.out.println(year + "\t闰年");
isRn = true;
}
else
{
System.out.println(year + "\t平年");
isRn = false;
}
while (month > 12 || month <= 0)
{
System.out.println("对不起,输入月份不正确!\n\n请重新输入:");
month = input.nextInt();
}
int yue = 0;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(month + "月\t共31天");
yue = 31;
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(month + "月\t共30天");
yue = 30;
break;
case 2:
if (isRn && month == 2)
{
System.out.println(month + "月\t共29天");
yue = 29;
}
else
{
System.out.println(month + "月\t共28天");
yue = 28;
}
break;
}
int sum = 0;
for (int i = 1900; i < year; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
{
sum = sum + 366;
}
else
{
sum = sum + 365;
}
}
for (int i = 1; i < month; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10
|| i == 12)
{
sum = sum + 31;
}
else if (i == 4 || i == 6 || i == 9 || i == 11)
{
sum = sum + 30;
}
else if (i == 2 && isRn)
{
sum = sum + 29;
}
else
{
sum = sum + 28;
}
}
System.out.println(year + "年" + month + "月距离1900年1月1日有" + sum + "天");
int firstdayofmonth;
int num = 1 + sum % 7;
if (num == 7)
{
firstdayofmonth = 0;
}
else
{
firstdayofmonth = num;
}
System.out.println("\n该月的第一天是星期" + firstdayofmonth);
System.out.println("\n星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
int x = sum % 7 + 1;
if (x != 7)
{
for (int i = 0; i < x; i++)
{
System.out.print("\t");
}
}
for (int i = 1; i <= yue; i++)
{
int everydayweek = (x + i - 1) % 7;
if (everydayweek == 6)
{
System.out.print(i + "\n");
}
else
{
System.out.print(i + "\t");
}
}
System.out.println("\n\n是否继续y/n");
answer = input.next();
}
System.out.println("\n程序结束!");
}
}