0% found this document useful (0 votes)
37 views3 pages

Number of Days To Date

This Java program accepts input of total days, year, and additional days (n) from the user. It then calculates the original date from the total days and the new date after adding n days. The key steps are: 1) using a while loop to calculate the month and date from total days; 2) adding n days to calculate the new date; 3) displaying both dates with month names.

Uploaded by

Tanushree Jati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

Number of Days To Date

This Java program accepts input of total days, year, and additional days (n) from the user. It then calculates the original date from the total days and the new date after adding n days. The key steps are: 1) using a while loop to calculate the month and date from total days; 2) adding n days to calculate the new date; 3) displaying both dates with month names.

Uploaded by

Tanushree Jati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;//Java package for Scanner

class Convert//Declaration of Class Name

int n,d,m,y,nn,n1,d1,k;//Initialization of Global variables

String
month[]={"","January","February","March","April","May","June","July","August","September","Ocob
er","November","December"};

Convert()//Declaration of Default Constructor

n=0;nn=0;

d=0;

m=0;

y=0;

void accept()//Declaration of Method to input the values

Scanner sc=new Scanner(System.in);//Activations of Scanner Class

System.out.println("ENTER THE TOTAL NUMBER OF DAYS:");

n=sc.nextInt();

System.out.println("ENTER THE YEAR:");

y=sc.nextInt();

System.out.println("ENTER THE N DAYS:");

nn=sc.nextInt();

void day_to_date()//Declaration of method to calculate the date and new date after n days

int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};//Number of Days in 12 month

if((y % 100 == 0 && y % 400 == 0) || y % 4 == 0)//To check if the given year is leap year or not

day[2]=29;
}

n1=n;//Copy of Number of days

k=0;

while(n1>day[k])//While-loop for the date of total number of days

n1=n1-day[k];

k++;

d1=n1;

n=n+nn;

m=0;

while(n>day[m])//While-loop for the date after n number of days

n=n-day[m];

m++;

d=n;

void display()//Method to display the Output

System.out.println("THE DATE IS: "+month[k] + d1+ ","+" "+y);

System.out.println("THE DATE AFTER N DAYS IS: "+month[m] + d+ ","+" "+y);

public static void main()

Convert obj=new Convert();// Method Calling Statement

obj.accept();

obj.day_to_date();

obj.display();
}

SL.NO NAME OF THE DATA PURPOSE


VARIABLES TYPE
1 n int To store the value for total
number of days
2 d int To store the value for total
number of days the copy of
date after n number of days
3 m int To store the value the copy
of number of months
4 y int To store the value the year
of the given date

5 nn int To store the value for N


days
6 n1 int To store the date of the
given number of days
7 d1 int To store the copy of n1

8 k int To store the value for k and


used as a increment value
9 month[] String To store the Name of 12
months
10 day[] int To store the value of
number of days in
12months

OUTPUT

You might also like