java算法小问题
Posted 宋建楠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java算法小问题相关的知识,希望对你有一定的参考价值。
import java.util.Scanner;
public class Day {
public static void main(String[] args) {
int[] days = {31,0,31,30,31,30,31,31,30,31,30,31};
Scanner in = new Scanner(System.in);
System.out.println("输入年份:");
int year = in.nextInt();
System.out.println("输入月份:");
int mouth = in.nextInt();
System.out.println("多少号:");
int day = in.nextInt();
if (year % 100 != 0) {
if (year % 4 == 0) {
days[1] = 29;
} else {
days[1] = 30;
}
} else {
if (year % 400 == 0) {
days[1] = 29;
} else {
days[1] = 30;
}
}
int all = 0;
mouth -= 2;
for (int i = 0; i <= mouth; i++) {
all += days[i];
}
System.out.println(all+day);
}
}
纯手打~~~
以上是关于java算法小问题的主要内容,如果未能解决你的问题,请参考以下文章