Java教程

java switch实现三天打鱼,两天晒网

本文主要是介绍java switch实现三天打鱼,两天晒网,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

import java.util.Scanner;

public class test05 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);

int sum=0;
int month,year,day,z;
z=0;
System.out.println("请输入年份:");
year=scanner.nextInt();
System.out.println("请输入月份:");
month=scanner.nextInt();
System.out.println("请输入日期:");
day=scanner.nextInt();
switch (month-1) {
case 11:
sum=sum+31;

case 10:
sum=sum+30;

case 9:
sum=sum+30;
case 8:
sum=sum+31;
case 7:
sum=sum+31;
case 6:
sum=sum+30;
case 5:
sum=sum+31;
case 4:
sum=sum+30;
case 3:
sum=sum+31;
case 2:
sum=sum+28;
case 1:
sum=sum+31;
case 0:
sum=sum+day;
default:

break;
}
if((year%4==0&&year/100!=0)||(year%4==0 && month>2)){
sum=sum+1;


}
if(sum%5==1 || sum%5==2 ||sum%5==3){
System.out.println("打鱼");
}else{
System.out.println("撒网");

}
System.out.println(sum);
}

}

 

这篇关于java switch实现三天打鱼,两天晒网的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!