Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Determining the Number of Days in a Month 
 

This section will show the way of counting the number of days of a month in the specified year.

 

Determining the Number of Days in a Month

                         

This section will show the way of counting the number of days of a month in the specified year. Following program takes the year as input through the keyboard and shows the number of days in the February month of the mentioned year if the year is valid other it will show the error message and terminate the program.

Code Description:

GregorianCalendar(year, Calendar.FEBRUARY, 1):
Above is the constructor of the GregorianCalendar class which create an instance for that. Year and month are specified in the constructor to create instance for finding the number of days in that month of the specified year. Here, the constructor takes three arguments as follows:

  • First is the year.
  • Second is the month (February).
  • And third is the initial date value.

Calendar.getActualMaximum(Calendar.DAY_OF_MONTH):
Above method finds and returns the maximum date value in the specified month of the specific year. It returns a integer value.

Here is the code of the program:

import java.util.*;
import java.io.*;

public class GettingDaysInMonth{
  public static void main(String[] argsthrows IOException{
    int year = 1;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter year : ");
    try{
      year = Integer.parseInt(in.readLine());
      if (year < 1900 || year > 2100){
        System.out.println("Please enter year greater than 1900 and less than 2100.");
        System.exit(0);
      }
    }
    catch(NumberFormatException ne){
      System.out.print(ne.getMessage() " is not a valid entry.");
      System.out.println("Please enter a four digit number.");
      System.exit(0);
    }
    Calendar cal = new GregorianCalendar(year, Calendar.FEBRUARY, 1);
    int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    System.out.print("Number of days : " + days);
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c reference methods references method user system using id package node create check if preferences for call exists to automatic

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

thanks alot

Posted by aabed on Monday, 12.22.08 @ 07:21am | #83050

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.