473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

validating a date (with leap year)

i am new to java and programming all together. any help would be appreciated.

i need to get it to input the date as so: mm/dd/yyyy and then output the date as so: February 29, 2004 is a date in a leap year. and if the date was before the year 1582 it leaves the date as it was entered: mm/dd/yyyy

i know that i need to use a switch statement. but i am lost right now. im not sure if i have the variables set right or if i even need the variables like that.

and if there is an easier way to post code please tell me how as well :D


package project_2app;

import java.util.*;

public class ValidateDates
{

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a date: ");
int year = input.nextInt();

//Check if the year is a leap year
boolean leapYear =
(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) && !(year <= 1582);

int jan = 1;
int feb = 2;
int mar = 3;
int april = 4;
int may = 5;
int june = 6;
int july = 7;
int aug = 8;
int sept = 9;
int oct = 10;
int nov = 11;
int dec = 12;
int month =



switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
break;
case 4:
case 6:
case 9:
case 11:
case 2:
break;
default:
System.out.println("Invalid Month");
break;
}


//Display results
System.out.println();

}

}
Feb 22 '10 #1
1 5976
ThatThatGuy
449 Expert 256MB
Writing such long codes for a simple is invariable...


you could just check this

Expand|Select|Wrap|Line Numbers
  1. if(year%4==0&&year>=1582)
that's for you to check for a leap year......

rest of what are you doing is going out of my head.............
Feb 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
9
by: Se'noj | last post by:
Hi all, In a program I am writing, I need to convert a date stored as an integer number of days into a standard gregorian format, with day zero being 1/1/1800. Can anyone help me with this? ...
5
by: Dennis M. Marks | last post by:
I've been updating by date stuff at my web site using much of the information obtained here. Would you please check it for any errors. The two pages are "Yearly Calendar" and "Date Calculator"....
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
7
by: Gucci | last post by:
<?php /** * check ine year is a leap year, and return the month day array * * @param int $year **the year must bigger than zero** * @return array */ function is_leap_year($year){...
2
by: owz | last post by:
Ok, I am making a program (java class file) 2 work out if a date entered is valid or invalid for the day, month year, and for leap years.. dd/mm/yyyy . I seem 2 have gotten it 2 validate the year...
0
debasisdas
by: debasisdas | last post by:
This article consistes of some of the frequently asked date related queries. Hope the users find it useful. ========================== 1.Determining the Date of the First and Last Occurrence of a...
2
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.