作业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;
}
}
}
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
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业(1)
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- 作业1
- CSS加载外部字体以及字体格式转换
- UITabBar 和 UINavigationBar 样式的定制
- zoj 3869 Ace of Aces
- 我来说说操作系统中 死锁与饥饿的区别辨析
- 转载:2014 Top Security Tools as Voted by ToolsWatch.org Readers
- 作业1
- 多线程对比linkedList和arrayList的add方法
- 关于HashMap问题二
- 一个链式存储的例子(图片)
- 如何让两个div处于一行
- PHP源码分析-变量的存储方式
- mini2440硬件篇之看门狗
- js 中读取JSON的方法探讨
- 黑马程序员——正则表达式