程序设计作业

内容:
中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
步骤:
1.算法分析根据题意可以将解题过程分为三步:
1)计算从2010年1月1日与指定日期相差多少天;
2)由于“打鱼”和“晒网”的周期为5天,所以将计算出的天数用5去除;
3)根据余数判断他是在“打鱼”还是在“晒网”;
若 余数为0,1,2,则他是在“打鱼”
否则 是在“晒网”
求从2010年1月1日与指定日期相差多少天,要判断经历年份中是否有闰年,二月为29天,平年为28天。闰年的方法可以用伪语句描述如下:
如果 ((年能被4除尽 且 不能被100除尽)或 能被400除尽)
则 该年是闰年;
否则 不是闰年。
2.概要设计
判断年份是否正确;
判断月份是否正确;
判断日期是否正确;
判断打鱼还是晒网;
判断是否是闰年;
计算距离输入日期多少天;
计算2010-(year-1)之间有多少天;
计算本年内该日期之前共有多少天;
判断每月有几天;
计算本年内该日期之前共有多少天。
在这里插入图片描述
3.测试在这里插入图片描述
在这里插入图片描述
4.源代码
package cxsjjc;
import java.util.Scanner;
public class Fish
{

public static void main (String[] args)
{
boolean flag = false;
flag=true;
while(flag)
{
Scanner scanner = new Scanner(System.in);
System.out.println(“输入年:”);
int year = scanner.nextInt();
if (year<2010)
{
System.out.println(“错误,请重新输入年”);
year = scanner.nextInt();
}
System.out.println(“输入月:”);
int month = scanner.nextInt();
if ( month < 1 | month > 12)
{
System.out.println(“错误,请重新输入月”);
month = scanner.nextInt();
}
System.out.println(“请输入日”);
int day = scanner.nextInt();
if (day > 31 | day < 1 )
{
System.out.println(“错误,请重新输入日”);
day = scanner.nextInt();
}
judge(getAllDays(year, month, day));
}
}
private static int getAllDays(int year, int month, int day) {
// TODO Auto-generated method stub
return 0;
}
//打鱼晒网
public static void judge(int day) {
int x = day % 5;
if (x >= 1 && x <= 3) {
System.out.println(“打鱼”);
} else if (x == 4 || x == 0) {
System.out.println(“晒网!”);
}
}
//闰年
public static boolean RunNian(int year) {
if ((year%40&&year%100!=0)||year%4000) {
return true;
}
return false;
}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值