Home > Java > javaTutorial > body text

Java calendar displays year and month

高洛峰
Release: 2016-11-21 11:46:26
Original
1456 people have browsed it

import java.util.Scanner;

class CalendarMain
{
//Main function entrance
public static void main(String[] args)
{
System.out.println("****Please enter the date ( The format is: 2011-01)*****");
Scanner sc = new Scanner(System.in);
String ym = sc.next();
//Intercept string
String[] yearMonth = ym .split("-");
                                                                      ‐                                                                  Convert the string into an integer type        int year = Integer.parseInt(yearMonth [0]);       int month =    Integer.parseInt(yearMonth [1]);      (year);
           Month.fun(month,year); 
                                                                                                                                              Month.fun                                                                                       Month.fun (int Year) {
if (year & gt; 1990 && years & lt; 10000) {
while (year & gt; = 1990) {
if (year % 4 == 0 && year % 100! = 0 || (year % year % 400 ==0 )){
                                                                                                              System.out.println("Please enter the query year is greater than or equal to 1990!"); }
}

//Get the number of days in a month and the total number of days
class Month
{
Public static void fun(int month,int year){
int monthDay = 0;
Year y = new Year();
int days = y.leapYear + (year - 1990)*365;
                                                                                                                                                                                                                                                                               days < 8 && i != 2){
                                                                                                               }
                                                                                                                   
                     days += i % 2 == 1                                                                                                                                                                                                                                                                                         year % 100 != 0 || (year % 400 ==0 )){
                                                                                                                     }else{
                          days += 28;                                                                                
           }
             Show.mothed(days,monthDay);
                                                                                                                                                System.out.println("Please enter the correct month!");
                                                                                                                                                                                          System.out.println(" One means starting from Monday
            int week = (days - monthDay) % 7 + 1;

        System.out.println("n Sunday" + "t Monday" + "t Tuesday" + "t Wednesday" +" t Thursday" + "t Friday" + "t Saturday"); .out.print(" "+"*"+"t");
                                                                                                                                                                                   . "t");                                                                                                                                if (i%7 == 0){
                            System.out.print(" n");
                                                                                

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!