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("\nDate = " +d +"-" +m +"-" +y); } }
ALGORITHM:-
1. Accept the day no. and the year from the user.
2. Check whether it is a leap year or not.
3. Count and print the corresponding date.
4. End
OUTPUT:-
Enter the Day No. : 230
Enter the Year : 2008
Date = 17-8-2008
Related Programs:-
★ Find the HCF & LCM of two numbers using recursion
★ Read a Date and give a day number
★ Multiply two Matrices
★ Search an element using Linear Search or Binary Search
★ Bubble Sort, Selection Sort, Insertion Sort and Quick Sort
exception error
ReplyDeletejhoot mat bol
ReplyDelete