作业1

来源:互联网 发布:linux更换网卡 编辑:程序博客网 时间:2024/05/22 17:47
package homework;


import java.util.Scanner;


public class Homework {
public void Year(int year) {
if (year % 4 == 0)
System.out.println("闰年");
else
System.out.println("平年");
}


public void Date(int year, int month, int date) {


int sum = 0;
int[] Month;
if (year % 4 == 0) {
Month = new int[] { -1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31 };
} else {
Month = new int[] { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31 };
}


for (int i = 1; i < month; i++)
sum += Month[i];
sum += date;
System.out.println("日期为该年第" + sum + "天");
}


public void Constellation(int month, int date) {


if (month == 1) {
if (date >= 20)
System.out.println("你的星座为水瓶座");
else
System.out.println("你的星座为魔羯座");
}
if (month == 2) {
if (date >= 19)
System.out.println("你的星座为双鱼座");
else
System.out.println("你的星座为水瓶座");
}
if (month == 3) {
if (date >= 21)
System.out.println("你的星座为白羊座");
else
System.out.println("你的星座为双鱼座");
}
if (month == 4) {
if (date >= 20)
System.out.println("你的星座为金牛座");
else
System.out.println("你的星座为白羊座");
}
if (month == 5) {
if (date >= 21)
System.out.println("你的星座为双子座");
else
System.out.println("你的星座为金牛座");
}
if (month == 6) {
if (date >= 22)
System.out.println("你的星座为巨蟹座");
else
System.out.println("你的星座为双子座");
}
if (month == 7) {
if (date >= 23)
System.out.println("你的星座为狮子座");
else
System.out.println("你的星座为巨蟹座");
}
if (month == 8) {
if (date >= 23)
System.out.println("你的星座为处女座");
else
System.out.println("你的星座为狮子座");
}
if (month == 9) {
if (date >= 23)
System.out.println("你的星座为天秤座");
else
System.out.println("你的星座为处女座");
}
if (month == 10) {
if (date >= 24)
System.out.println("你的星座为天蝎座");
else
System.out.println("你的星座为天秤座");
}
if (month == 11) {
if (date >= 23)
System.out.println("你的星座为射手座");
else
System.out.println("你的星座为天蝎座");
}
if (month == 12) {
if (date >= 22)
System.out.println("你的星座为魔羯座");
else
System.out.println("你的星座为射手座");
}


}


public static void main(String[] args) {
System.out.println("请选择功能");
System.out.println("1.判断平年或者闰年");
System.out.println("2.判断日期为该年第几天");
System.out.println("3.判断星座");
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("请输入年份");
int year1 = input.nextInt();
new Homework().Year(year1);
break;
case 2:
System.out.print("请输入年份:");
int year2 = input.nextInt();
System.out.print("请输入月份:");
int month2 = input.nextInt();
System.out.print("请输入日期:");
int date2 = input.nextInt();
new Homework().Date(year2, month2, date2);
break;
case 3:
System.out.print("请输入月份:");
int month3 = input.nextInt();
System.out.print("请输入日期:");
int date3 = input.nextInt();
new Homework().Constellation( month3, date3);
break;
default:
System.out.print("输入错误");
break;
}
}
}
0 0
原创粉丝点击