Java -- input a year from the keyboard and a month (number) to output the number of days of the month.

Source: Internet
Author: User

[Java]
/* (Start of program header annotation) </p> <p> * copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* Author: Li Zhaoqing
* Completion date: January 1, September 22, 2012
* Input description:
* Problem description and output: run java: enter a year on the keyboard, a month (number), and the number of days of the month.
* End the comment in the program Header
*/
 
Import javax. swing. JOptionPane;
Public class Num {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
String str = JOptionPane. showInputDialog ("Enter the year to be determined ;");

Int y = Integer. parseInt (str );

System. out. println ("the year you entered is:" + y );

String strm = JOptionPane. showInputDialog ("Enter the month to be judged ;");

Int m = Integer. parseInt (strm );

System. out. println ("the month you entered is:" + m );


If (jud (y ))
{
System. out. println (y + "is a leap year .");
}
Else
{
System. out. println (y + "not a leap year ");
}
Int d = fig (m );

If (jud (y ))
{
If (m = 2)
{
++ D;
}
System. out. println ("the number of days you entered this month is:" + d );
}
Else
{
System. out. println ("the number of days you entered this month is:" + d );
}


}


Public static boolean jud (int y)
{
If (y % 400 = 0 | y % 4 = 0 & y % 100! = 0)
{
Return true;
}
Else
{
Return false;
}
}



Public static int fig (int m)
{
Switch (m)
{
Case 1:
Return 31;
Case 2:
Return 28;
Case 3:
Return 31;
Case 4:
Return 30;
Case 5:
Return 31;
Case 6:
Return 30;
Case 7:
Return 31;
Case 8:
Return 31;
Case 9:
Return 30;
Case 10:
Return 31;
Case 11:
Return 30;
Case 12:
Return 31;
Default:
System. out. println ("sorry, the month you entered is incorrect! ");
Return 0;
}
}
}

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.