码迷,mamicode.com
首页 > 编程语言 > 详细

java算法小问题

时间:2017-11-14 22:36:46      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:小问题   ==   static   next   多少   new   tin   void   port   

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算法小问题

标签:小问题   ==   static   next   多少   new   tin   void   port   

原文地址:http://www.cnblogs.com/s1104119631/p/7834611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!