Java code to read the day Number and year its corresponding date

/*
Program to read the day No. and year its corresponding date.
*/
import java.io.*;
class dayNo2date
{
public static void main(String args[]) throws IOException
{
dayNo2date call = new dayNo2date();
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
// Read day no. and year
System.out.print("Enter the Day No. : ");
int n = Integer.parseInt(br.readLine());
System.out.print("Enter the Year : ");
int y = Integer.parseInt(br.readLine());
call.toDate(n,y);
}
public void toDate(int n, int y)
{
int a[] = {31,28,31,30,31,30,31,31,30,31,30,31};
if(y%4==0) // Check for leap year
a[1] = 29;
int s=0, m=0;
// Calculate Month
while(s<n)
s+=a[m++];
s-=a[m-1];
int d = n-s; // Calculate Day
// Print the Date
System.out.println("
Date = " +d +"-" +m +"-" +y);
}
}

/**
* ALGORITHM :
* ---------
* 1. Start
14* 2.
* 3.
* 4.
* 5.
*/
Accept the day no. and the year from the user.
Check whether it is a leap year or not.
Count and print the corresponding date.
End
/*
OUTPUT :
------
Enter the Day No. : 230
Enter the Year : 2008
Date = 17-8-2008
*/


Related Posts by Categories

and
corresponding

    0 komentar:

    Posting Komentar