SlideShare a Scribd company logo
Need to make a Java program which calculates the number of days between two dates. I am NOT
able to use anything too advanced yet such as import.java.util.Calender, import.java.util.Date; or
import.java.util.GregorianCalender; Here are a couple of examples of what is should look like
when complete. I am having troubles getting my calculations to come out correctly. I’ve also
written the code I have so far.
EXAMPLE
“Enter first date now:
Enter Month: 1
Enter Day: 1
Enter Year: 1900
Enter the second date:
Enter Month: 1
Enter Day: 1
Enter Year: 2400
The first date is: 1/1/1900
The other date is: 1/1/2400
The total number of days between the dates is 182621”
AND
“Enter first date now:
Enter Month: 2
Enter Day: 23
Enter Year: 2016
Enter the second date:
Enter Month: 11
Enter Day: 30
Enter Year: 1955
The first date is: 2/23/2016
The other date is: 11/30/1955
The total number of days between the dates is 22000”
Here is what I have so far:
Import java.util.Scanner;
Public class dates {
Public static void main ( String args [] ) {
int monthOne;
int monthTwo;
int dayOne;
int dayTwo;
intyearOne;
intyearTwo;
Scanner get = new Scanner (System.in );
System.out.println ( “Enter first date now: “ );
do {
System.out.print ( “Enter Month: “);
monthOne = get.nextInt();
System.out.print ( “Enter Day: “ );
dayOne = get.nextInt();
System.out.print ( “Enter Year : “ );
yearOne = get.nextInt();
if (monthOne < 1 || monthOne > 12 ) {
System.out.printf ( “%d is not a valid month ”, monthOne ); }
If ( (!(yearOne % 4 == 0 && yearOne & 100 !=0 || yearOne % 400 == 0) && (monthOne == 2
&& dayOne >= 29)) || ((yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 == 0) &&
(monthOne == 2 && dayOne >= 30))) {
System.out.printf ( “%d is not a valid day. ”, dayOne ); }
If ( (monthOne == 4 && dayOne > 30) || (monthOne ==6 && dayOne > 30) || (monthOne == 9
&& dayOne > 30) || (monthOne == 11 && dayOne > 30) || (dayOne < 1 || dayOne > 31)) {
System.out.printf ( “%d is not a valid day. ”, dayOne );
If ( yearOne < 1900 || yearOne > 2400 ) {
System.out.printf ( “%d is not a valid year. ”, yearOne ); }
} while (( (!(yearOne % 4 == 0 && yearOne % 100 !=0 || yearOne % 400 == 0) && (monthOne
== 2 && dayOne >= 29)) || ((yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 ==
0) && (monthOne == 2 && dayOne >= 30 )) || (monthOne == 4 && dayOne > 30) || (monthOne
== 6 && dayOne > 30) || (monthOne == 9 && dayOne > 30) || (monthOne == 11 && dayOne >
30) || (monthOne < 1 || monthOne > 12) || (dayOne < 1 || dayOne > 31) || (yearOne < 1900 ||
yearOne > 2400) ));
System.out.printf ( “ Enter the second date:  ” );
do {
System.out.print ( “Enter Month: “);
monthTwo = get.nextInt();
System.out.print ( “Enter Day: “ );
dayTwo = get.nextInt();
System.out.print ( “Enter Year : “ );
yearTwo = get.nextInt();
if (monthTwo < 1 || monthTwo > 12 ) {
System.out.printf ( “%d is not a valid month ”, monthTwo ); }
If ( (!(yearTwo % 4 == 0 && yearTwo & 100 !=0 || yearTwo % 400 == 0) && (monthTwo == 2
&& dayTwo >= 29)) || ((yearTwo % 4 == 0 && yearTwo % 100 != 0 || yearTwo % 400 == 0)
&& (monthTwo == 2 && dayTwo >= 30))) {
System.out.printf ( “%d is not a valid day. ”, dayTwo ); }
If ( (monthTwo == 4 && dayTwo > 30) || (monthTwo ==6 && dayTwo > 30) || (monthTwo ==
9 && dayTwo > 30) || (monthTwo == 11 && dayTwo > 30) || (dayTwo < 1 || dayTwo > 31)) {
System.out.printf ( “%d is not a valid day. ”, dayTwo );
If ( yearTwo < 1900 || yearTwo > 2400 ) {
System.out.printf ( “%d is not a valid year. ”, yearTwo ); }
} while (( (!(yearTwo % 4 == 0 && yearTwo % 100 !=0 || yearTwo % 400 == 0) &&
(monthTwo == 2 && dayTwo >= 29)) || ((yearTwo % 4 == 0 && yearTwo % 100 != 0 ||
yearTwo % 400 == 0) && (monthTwo == 2 && dayTwo >= 30 )) || (monthTwo == 4 &&
dayTwo > 30) || (monthTwo == 6 && dayTwo > 30) || (monthTwo == 9 && dayTwo > 30) ||
(monthTwo == 11 && dayTwo > 30) || (monthTwo < 1 || monthTwo > 12) || (dayTwo < 1 ||
dayTwo > 31) || (yearTwo < 1900 || yearTwo > 2400) ));
System.out.printf ( “ The first date is: %d/%d/%d ”, monthOne, dayOne, yearOne );
System.out.printf ( “ The other date is: %d/%d/%d ”, monthTwo, dayTwo, yearTwo );
int totalDayOne = 0;
int numDaysJan = dayOne;
int numDaysFeb = 31 + dayOne;
int numDaysMar = 31 + 28 + dayOne;
int numDaysApr = 31 + 28 + 31 + dayOne;
int numDaysMay = 31 + 28 + 31 + 30 + dayOne;
int numDaysJun = 31 + 28 + 31 + 30 + 31 + dayOne;
int numDaysJul = 31 + 28 + 31 + 30 + 31 + 30 + dayOne;
int numDaysAug = 31 + 28 + 31 + 30 + 31 + 30 + 31 + dayOne;
int numDaysSep = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + dayOne;
int numDaysOct = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + dayOne;
int numDaysNov = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + dayOne;
int numDaysDec = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + dayOne;
int totalDayTwo = 0;
int numDaysJanTwo = dayTwo;
int numDaysFebTwo = 31 + dayTwo;
int numDaysMarTwo = 31 + 28 + dayTwo;
int numDaysAprTwo = 31 + 28 + 31 + dayTwo;
int numDaysMayTwo = 31 + 28 + 31 + 30 + dayTwo;
int numDaysJunTwo = 31 + 28 + 31 + 30 + 31 + dayTwo;
int numDaysJulTwo = 31 + 28 + 31 + 30 + 31 + 30 + dayTwo;
int numDaysAugTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + dayTwo;
int numDaysSepTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + dayTwo;
int numDaysOctTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + dayTwo;
int numDaysNovTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + dayTwo;
int numDaysDecTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + dayTwo;
if ( monthOne == 1 ) {
totalDayOne += numDaysJan;
}
if ( monthOne == 2 ) {
totalDayOne += numDaysFeb;
}
if ( monthOne == 3 ) {
totalDayOne += numDaysMar;
}
if ( monthOne == 4 ) {
totalDayOne += numDaysApr;
}
If ( monthOne == 5 ) {
totalDayOne += numDaysMay;
}
if (monthOne == 6 ) {
totalDayOne += numDaysJun;
}
if ( monthOne == 7 ) {
totalDayOne += numDaysJul;
}
if ( monthOne == 8 ) {
totalDayOne += numDaysAug;
}
if ( monthOne == 9 ) {
totalDayOne += numDaysSep;
}
if ( monthOne == 10 ) {
totalDayOne += numDaysOct;
}
if (monthOne == 11 ) {
totalDayOne += numDaysNov;
}
if (monthOne == 12 ) {
totalDayOne += numDaysDec;
}
if ( monthTwo == 1 ) {
totalDayTwo += numDaysJanTwo;
}
if ( monthTwo == 2 ) {
totalDayTwo += numDaysFebTwo;
}
if ( monthTwo == 3 ) {
totalDayTwo += numDaysMarTwo;
}
if ( monthTwo == 4 ) {
totalDayTwo += numDaysAprTwo;
}
If ( monthTwo == 5 ) {
totalDayTwo += numDaysMayTwo;
}
if (monthTwo == 6 ) {
totalDayTwo += numDaysJunTwo;
}
if ( monthTwo == 7 ) {
totalDayTwo += numDaysJulTwo;
}
if ( monthTwo == 8 ) {
totalDayTwo += numDaysAugTwo;
}
if ( monthTwo == 9 ) {
totalDayTwo += numDaysSepTwo;
}
if ( monthTwo == 10 ) {
totalDayTwo += numDaysOctTwo;
}
if (monthTwo == 11 ) {
totalDayTwo += numDaysNovTwo;
}
if (monthTwo == 12 ) {
totalDayTwo += numDaysDecTwo;
}
int daysBetween = totalDayOne – totalDayTwo;
if ( totalDayOne < totalDayTwo ) {
daysBetween = totalDayTwo – totalDayOne;
}
int daysTotal = 0;
while ( yearOne < yearTwo ) {
yearOne++;
if ( yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 == 0)
daysTotal += 366;
else
daysTotal += 365;
}
while ( yearTwo < yearOne ) {
yearTwo++;
if ( yearTwo % 4 == 0 && yearTwo % 100 != 0 || yearTwo % 400 == 0)
daysTotal += 366;
else
daysTotal += 365;
}
System.out.printf ( “ The total number of days between the dates is %d ”, daysTotal +
daysBetween);
}
}
Solution
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class NewDateDifference {
public static void main(String[] args) {
System.out.print("Insert first date : ");
Scanner s = new Scanner(System.in);
String[] eingabe1 = new String[3];
while (s.hasNext()) {
int i = 0;
insert1[i] = s.next();
if (!s.hasNext()) {
s.close();
break;
}
i++;
}
System.out.print("Insert second date : ");
Scanner t = new Scanner(System.in);
String[] insert2 = new String[3];
while (t.hasNext()) {
int i = 0;
insert2[i] = t.next();
if (!t.hasNext()) {
t.close();
break;
}
i++;
}
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(insert1[0]));
cal.set(Calendar.MONTH, Integer.parseInt(insert1[1]));
cal.set(Calendar.YEAR, Integer.parseInt(insert1[2]));
Date firstDate = cal.getTime();
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(insert2[0]));
cal.set(Calendar.MONTH, Integer.parseInt(insert2[1]));
cal.set(Calendar.YEAR, Integer.parseInt(insert2[2]));
Date secondDate = cal.getTime();
long diff = secondDate.getTime() - firstDate.getTime();
System.out.println ("Days: " + diff / 1000 / 60 / 60 / 24);
}
}

More Related Content

Similar to Need to make a Java program which calculates the number of days betw.pdf

Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdfDate.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
angelfragranc
 
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri FontainePython and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
Citus Data
 
Date class that represents a date consisting of a year, month, and a.pdf
Date class that represents a date consisting of a year, month, and a.pdfDate class that represents a date consisting of a year, month, and a.pdf
Date class that represents a date consisting of a year, month, and a.pdf
anilgoelslg
 
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdfpublicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
mukhtaransarcloth
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
Igalia
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflow
Mark Proctor
 
RではじめるTwitter解析
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析
Takeshi Arabiki
 
Excel class notes
Excel class notesExcel class notes
Excel class notes
Sneha kamineni
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
anonaeon
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
Ganesh Samarthyam
 
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Faysal Shaarani (MBA)
 
機械学習と自動微分
機械学習と自動微分機械学習と自動微分
機械学習と自動微分
Ichigaku Takigawa
 
Ta 2018-1-2404-24109 algebra lineal
Ta 2018-1-2404-24109 algebra linealTa 2018-1-2404-24109 algebra lineal
Ta 2018-1-2404-24109 algebra lineal
jhonatanVsquezArriag
 
ThreeTen
ThreeTenThreeTen
ThreeTen
彥彬 洪
 
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
NHN FORWARD
 

Similar to Need to make a Java program which calculates the number of days betw.pdf (16)

Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdfDate.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
 
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri FontainePython and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
Python and PostgreSQL: Let's Work Together! | PyConFr 2018 | Dimitri Fontaine
 
Date class that represents a date consisting of a year, month, and a.pdf
Date class that represents a date consisting of a year, month, and a.pdfDate class that represents a date consisting of a year, month, and a.pdf
Date class that represents a date consisting of a year, month, and a.pdf
 
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdfpublicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
publicclass Date {privatestatic String DATE_SEPARATOR = ;pr.pdf
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
 
17 ruby date time
17 ruby date time17 ruby date time
17 ruby date time
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflow
 
RではじめるTwitter解析
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析
 
Excel class notes
Excel class notesExcel class notes
Excel class notes
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)Date and Timestamp Types In Snowflake (By Faysal Shaarani)
Date and Timestamp Types In Snowflake (By Faysal Shaarani)
 
機械学習と自動微分
機械学習と自動微分機械学習と自動微分
機械学習と自動微分
 
Ta 2018-1-2404-24109 algebra lineal
Ta 2018-1-2404-24109 algebra linealTa 2018-1-2404-24109 algebra lineal
Ta 2018-1-2404-24109 algebra lineal
 
ThreeTen
ThreeTenThreeTen
ThreeTen
 
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
 

More from anjandavid

I am exploring the basic components of advanced broadband networks..pdf
I am exploring the basic components of advanced broadband networks..pdfI am exploring the basic components of advanced broadband networks..pdf
I am exploring the basic components of advanced broadband networks..pdf
anjandavid
 
How many different instances of the ls command are installed on .pdf
How many different instances of the ls command are installed on .pdfHow many different instances of the ls command are installed on .pdf
How many different instances of the ls command are installed on .pdf
anjandavid
 
How are the Allen Bradley SLC 500 program files organizedSolutio.pdf
How are the Allen Bradley SLC 500 program files organizedSolutio.pdfHow are the Allen Bradley SLC 500 program files organizedSolutio.pdf
How are the Allen Bradley SLC 500 program files organizedSolutio.pdf
anjandavid
 
Hi, I need help please, this is about KaseyaWich o the following .pdf
Hi, I need help please, this is about KaseyaWich o the following .pdfHi, I need help please, this is about KaseyaWich o the following .pdf
Hi, I need help please, this is about KaseyaWich o the following .pdf
anjandavid
 
How did WWI and its aftermath provide African Americans with opportu.pdf
How did WWI and its aftermath provide African Americans with opportu.pdfHow did WWI and its aftermath provide African Americans with opportu.pdf
How did WWI and its aftermath provide African Americans with opportu.pdf
anjandavid
 
For problems 3 and 4, consider the following functions that implemen.pdf
For problems 3 and 4, consider the following functions that implemen.pdfFor problems 3 and 4, consider the following functions that implemen.pdf
For problems 3 and 4, consider the following functions that implemen.pdf
anjandavid
 
Give an example of a system. What are the Components, Attributes,.pdf
Give an example of a system. What are the Components, Attributes,.pdfGive an example of a system. What are the Components, Attributes,.pdf
Give an example of a system. What are the Components, Attributes,.pdf
anjandavid
 
Discuss the attribution process and attribution errorsSolution.pdf
Discuss the attribution process and attribution errorsSolution.pdfDiscuss the attribution process and attribution errorsSolution.pdf
Discuss the attribution process and attribution errorsSolution.pdf
anjandavid
 
E, an individual, received $40,000 of non-eligible dividends from Ca.pdf
E, an individual, received $40,000 of non-eligible dividends from Ca.pdfE, an individual, received $40,000 of non-eligible dividends from Ca.pdf
E, an individual, received $40,000 of non-eligible dividends from Ca.pdf
anjandavid
 
Describe one (1) example in which laws granting freedom of the press.pdf
Describe one (1) example in which laws granting freedom of the press.pdfDescribe one (1) example in which laws granting freedom of the press.pdf
Describe one (1) example in which laws granting freedom of the press.pdf
anjandavid
 
Briefly discuss 3–5 key trends in the modern health care operation.pdf
Briefly discuss 3–5 key trends in the modern health care operation.pdfBriefly discuss 3–5 key trends in the modern health care operation.pdf
Briefly discuss 3–5 key trends in the modern health care operation.pdf
anjandavid
 
A student obtained the following data Mass of water in calorimeter 3.pdf
A student obtained the following data Mass of water in calorimeter 3.pdfA student obtained the following data Mass of water in calorimeter 3.pdf
A student obtained the following data Mass of water in calorimeter 3.pdf
anjandavid
 
All answers must be in your own words.What is importance of the Wa.pdf
All answers must be in your own words.What is importance of the Wa.pdfAll answers must be in your own words.What is importance of the Wa.pdf
All answers must be in your own words.What is importance of the Wa.pdf
anjandavid
 
Can someone please fix my code for a hashtable frequencey counter I.pdf
Can someone please fix my code for a hashtable frequencey counter I.pdfCan someone please fix my code for a hashtable frequencey counter I.pdf
Can someone please fix my code for a hashtable frequencey counter I.pdf
anjandavid
 
A polycationic mRNA contains two or more promoter sequences. True Fal.pdf
A polycationic mRNA contains two or more promoter sequences. True Fal.pdfA polycationic mRNA contains two or more promoter sequences. True Fal.pdf
A polycationic mRNA contains two or more promoter sequences. True Fal.pdf
anjandavid
 
Why are electrons shared in molecular compoundsWhy are electron.pdf
Why are electrons shared in molecular compoundsWhy are electron.pdfWhy are electrons shared in molecular compoundsWhy are electron.pdf
Why are electrons shared in molecular compoundsWhy are electron.pdf
anjandavid
 
Which of these isare true of UDPa. It provides reliability, flow-c.pdf
Which of these isare true of UDPa. It provides reliability, flow-c.pdfWhich of these isare true of UDPa. It provides reliability, flow-c.pdf
Which of these isare true of UDPa. It provides reliability, flow-c.pdf
anjandavid
 
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdfWhich liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
anjandavid
 
What is employee involvement What are some of the benefits of invol.pdf
What is employee involvement What are some of the benefits of invol.pdfWhat is employee involvement What are some of the benefits of invol.pdf
What is employee involvement What are some of the benefits of invol.pdf
anjandavid
 
What are the pros and cons of technological leader versus technologi.pdf
What are the pros and cons of technological leader versus technologi.pdfWhat are the pros and cons of technological leader versus technologi.pdf
What are the pros and cons of technological leader versus technologi.pdf
anjandavid
 

More from anjandavid (20)

I am exploring the basic components of advanced broadband networks..pdf
I am exploring the basic components of advanced broadband networks..pdfI am exploring the basic components of advanced broadband networks..pdf
I am exploring the basic components of advanced broadband networks..pdf
 
How many different instances of the ls command are installed on .pdf
How many different instances of the ls command are installed on .pdfHow many different instances of the ls command are installed on .pdf
How many different instances of the ls command are installed on .pdf
 
How are the Allen Bradley SLC 500 program files organizedSolutio.pdf
How are the Allen Bradley SLC 500 program files organizedSolutio.pdfHow are the Allen Bradley SLC 500 program files organizedSolutio.pdf
How are the Allen Bradley SLC 500 program files organizedSolutio.pdf
 
Hi, I need help please, this is about KaseyaWich o the following .pdf
Hi, I need help please, this is about KaseyaWich o the following .pdfHi, I need help please, this is about KaseyaWich o the following .pdf
Hi, I need help please, this is about KaseyaWich o the following .pdf
 
How did WWI and its aftermath provide African Americans with opportu.pdf
How did WWI and its aftermath provide African Americans with opportu.pdfHow did WWI and its aftermath provide African Americans with opportu.pdf
How did WWI and its aftermath provide African Americans with opportu.pdf
 
For problems 3 and 4, consider the following functions that implemen.pdf
For problems 3 and 4, consider the following functions that implemen.pdfFor problems 3 and 4, consider the following functions that implemen.pdf
For problems 3 and 4, consider the following functions that implemen.pdf
 
Give an example of a system. What are the Components, Attributes,.pdf
Give an example of a system. What are the Components, Attributes,.pdfGive an example of a system. What are the Components, Attributes,.pdf
Give an example of a system. What are the Components, Attributes,.pdf
 
Discuss the attribution process and attribution errorsSolution.pdf
Discuss the attribution process and attribution errorsSolution.pdfDiscuss the attribution process and attribution errorsSolution.pdf
Discuss the attribution process and attribution errorsSolution.pdf
 
E, an individual, received $40,000 of non-eligible dividends from Ca.pdf
E, an individual, received $40,000 of non-eligible dividends from Ca.pdfE, an individual, received $40,000 of non-eligible dividends from Ca.pdf
E, an individual, received $40,000 of non-eligible dividends from Ca.pdf
 
Describe one (1) example in which laws granting freedom of the press.pdf
Describe one (1) example in which laws granting freedom of the press.pdfDescribe one (1) example in which laws granting freedom of the press.pdf
Describe one (1) example in which laws granting freedom of the press.pdf
 
Briefly discuss 3–5 key trends in the modern health care operation.pdf
Briefly discuss 3–5 key trends in the modern health care operation.pdfBriefly discuss 3–5 key trends in the modern health care operation.pdf
Briefly discuss 3–5 key trends in the modern health care operation.pdf
 
A student obtained the following data Mass of water in calorimeter 3.pdf
A student obtained the following data Mass of water in calorimeter 3.pdfA student obtained the following data Mass of water in calorimeter 3.pdf
A student obtained the following data Mass of water in calorimeter 3.pdf
 
All answers must be in your own words.What is importance of the Wa.pdf
All answers must be in your own words.What is importance of the Wa.pdfAll answers must be in your own words.What is importance of the Wa.pdf
All answers must be in your own words.What is importance of the Wa.pdf
 
Can someone please fix my code for a hashtable frequencey counter I.pdf
Can someone please fix my code for a hashtable frequencey counter I.pdfCan someone please fix my code for a hashtable frequencey counter I.pdf
Can someone please fix my code for a hashtable frequencey counter I.pdf
 
A polycationic mRNA contains two or more promoter sequences. True Fal.pdf
A polycationic mRNA contains two or more promoter sequences. True Fal.pdfA polycationic mRNA contains two or more promoter sequences. True Fal.pdf
A polycationic mRNA contains two or more promoter sequences. True Fal.pdf
 
Why are electrons shared in molecular compoundsWhy are electron.pdf
Why are electrons shared in molecular compoundsWhy are electron.pdfWhy are electrons shared in molecular compoundsWhy are electron.pdf
Why are electrons shared in molecular compoundsWhy are electron.pdf
 
Which of these isare true of UDPa. It provides reliability, flow-c.pdf
Which of these isare true of UDPa. It provides reliability, flow-c.pdfWhich of these isare true of UDPa. It provides reliability, flow-c.pdf
Which of these isare true of UDPa. It provides reliability, flow-c.pdf
 
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdfWhich liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
Which liquid would BaCl Which liquid would BaCl 4. Which liquid.pdf
 
What is employee involvement What are some of the benefits of invol.pdf
What is employee involvement What are some of the benefits of invol.pdfWhat is employee involvement What are some of the benefits of invol.pdf
What is employee involvement What are some of the benefits of invol.pdf
 
What are the pros and cons of technological leader versus technologi.pdf
What are the pros and cons of technological leader versus technologi.pdfWhat are the pros and cons of technological leader versus technologi.pdf
What are the pros and cons of technological leader versus technologi.pdf
 

Recently uploaded

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

Need to make a Java program which calculates the number of days betw.pdf

  • 1. Need to make a Java program which calculates the number of days between two dates. I am NOT able to use anything too advanced yet such as import.java.util.Calender, import.java.util.Date; or import.java.util.GregorianCalender; Here are a couple of examples of what is should look like when complete. I am having troubles getting my calculations to come out correctly. I’ve also written the code I have so far. EXAMPLE “Enter first date now: Enter Month: 1 Enter Day: 1 Enter Year: 1900 Enter the second date: Enter Month: 1 Enter Day: 1 Enter Year: 2400 The first date is: 1/1/1900 The other date is: 1/1/2400 The total number of days between the dates is 182621” AND “Enter first date now: Enter Month: 2 Enter Day: 23 Enter Year: 2016 Enter the second date: Enter Month: 11 Enter Day: 30 Enter Year: 1955 The first date is: 2/23/2016 The other date is: 11/30/1955 The total number of days between the dates is 22000” Here is what I have so far: Import java.util.Scanner; Public class dates { Public static void main ( String args [] ) { int monthOne; int monthTwo;
  • 2. int dayOne; int dayTwo; intyearOne; intyearTwo; Scanner get = new Scanner (System.in ); System.out.println ( “Enter first date now: “ ); do { System.out.print ( “Enter Month: “); monthOne = get.nextInt(); System.out.print ( “Enter Day: “ ); dayOne = get.nextInt(); System.out.print ( “Enter Year : “ ); yearOne = get.nextInt(); if (monthOne < 1 || monthOne > 12 ) { System.out.printf ( “%d is not a valid month ”, monthOne ); } If ( (!(yearOne % 4 == 0 && yearOne & 100 !=0 || yearOne % 400 == 0) && (monthOne == 2 && dayOne >= 29)) || ((yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 == 0) && (monthOne == 2 && dayOne >= 30))) { System.out.printf ( “%d is not a valid day. ”, dayOne ); } If ( (monthOne == 4 && dayOne > 30) || (monthOne ==6 && dayOne > 30) || (monthOne == 9 && dayOne > 30) || (monthOne == 11 && dayOne > 30) || (dayOne < 1 || dayOne > 31)) { System.out.printf ( “%d is not a valid day. ”, dayOne ); If ( yearOne < 1900 || yearOne > 2400 ) { System.out.printf ( “%d is not a valid year. ”, yearOne ); } } while (( (!(yearOne % 4 == 0 && yearOne % 100 !=0 || yearOne % 400 == 0) && (monthOne == 2 && dayOne >= 29)) || ((yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 == 0) && (monthOne == 2 && dayOne >= 30 )) || (monthOne == 4 && dayOne > 30) || (monthOne == 6 && dayOne > 30) || (monthOne == 9 && dayOne > 30) || (monthOne == 11 && dayOne > 30) || (monthOne < 1 || monthOne > 12) || (dayOne < 1 || dayOne > 31) || (yearOne < 1900 || yearOne > 2400) )); System.out.printf ( “ Enter the second date: ” ); do { System.out.print ( “Enter Month: “); monthTwo = get.nextInt(); System.out.print ( “Enter Day: “ ); dayTwo = get.nextInt();
  • 3. System.out.print ( “Enter Year : “ ); yearTwo = get.nextInt(); if (monthTwo < 1 || monthTwo > 12 ) { System.out.printf ( “%d is not a valid month ”, monthTwo ); } If ( (!(yearTwo % 4 == 0 && yearTwo & 100 !=0 || yearTwo % 400 == 0) && (monthTwo == 2 && dayTwo >= 29)) || ((yearTwo % 4 == 0 && yearTwo % 100 != 0 || yearTwo % 400 == 0) && (monthTwo == 2 && dayTwo >= 30))) { System.out.printf ( “%d is not a valid day. ”, dayTwo ); } If ( (monthTwo == 4 && dayTwo > 30) || (monthTwo ==6 && dayTwo > 30) || (monthTwo == 9 && dayTwo > 30) || (monthTwo == 11 && dayTwo > 30) || (dayTwo < 1 || dayTwo > 31)) { System.out.printf ( “%d is not a valid day. ”, dayTwo ); If ( yearTwo < 1900 || yearTwo > 2400 ) { System.out.printf ( “%d is not a valid year. ”, yearTwo ); } } while (( (!(yearTwo % 4 == 0 && yearTwo % 100 !=0 || yearTwo % 400 == 0) && (monthTwo == 2 && dayTwo >= 29)) || ((yearTwo % 4 == 0 && yearTwo % 100 != 0 || yearTwo % 400 == 0) && (monthTwo == 2 && dayTwo >= 30 )) || (monthTwo == 4 && dayTwo > 30) || (monthTwo == 6 && dayTwo > 30) || (monthTwo == 9 && dayTwo > 30) || (monthTwo == 11 && dayTwo > 30) || (monthTwo < 1 || monthTwo > 12) || (dayTwo < 1 || dayTwo > 31) || (yearTwo < 1900 || yearTwo > 2400) )); System.out.printf ( “ The first date is: %d/%d/%d ”, monthOne, dayOne, yearOne ); System.out.printf ( “ The other date is: %d/%d/%d ”, monthTwo, dayTwo, yearTwo ); int totalDayOne = 0; int numDaysJan = dayOne; int numDaysFeb = 31 + dayOne; int numDaysMar = 31 + 28 + dayOne; int numDaysApr = 31 + 28 + 31 + dayOne; int numDaysMay = 31 + 28 + 31 + 30 + dayOne; int numDaysJun = 31 + 28 + 31 + 30 + 31 + dayOne; int numDaysJul = 31 + 28 + 31 + 30 + 31 + 30 + dayOne; int numDaysAug = 31 + 28 + 31 + 30 + 31 + 30 + 31 + dayOne; int numDaysSep = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + dayOne; int numDaysOct = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + dayOne; int numDaysNov = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + dayOne; int numDaysDec = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + dayOne; int totalDayTwo = 0; int numDaysJanTwo = dayTwo;
  • 4. int numDaysFebTwo = 31 + dayTwo; int numDaysMarTwo = 31 + 28 + dayTwo; int numDaysAprTwo = 31 + 28 + 31 + dayTwo; int numDaysMayTwo = 31 + 28 + 31 + 30 + dayTwo; int numDaysJunTwo = 31 + 28 + 31 + 30 + 31 + dayTwo; int numDaysJulTwo = 31 + 28 + 31 + 30 + 31 + 30 + dayTwo; int numDaysAugTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + dayTwo; int numDaysSepTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + dayTwo; int numDaysOctTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + dayTwo; int numDaysNovTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + dayTwo; int numDaysDecTwo = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + dayTwo; if ( monthOne == 1 ) { totalDayOne += numDaysJan; } if ( monthOne == 2 ) { totalDayOne += numDaysFeb; } if ( monthOne == 3 ) { totalDayOne += numDaysMar; } if ( monthOne == 4 ) { totalDayOne += numDaysApr; } If ( monthOne == 5 ) { totalDayOne += numDaysMay; } if (monthOne == 6 ) { totalDayOne += numDaysJun; } if ( monthOne == 7 ) { totalDayOne += numDaysJul; } if ( monthOne == 8 ) { totalDayOne += numDaysAug; } if ( monthOne == 9 ) {
  • 5. totalDayOne += numDaysSep; } if ( monthOne == 10 ) { totalDayOne += numDaysOct; } if (monthOne == 11 ) { totalDayOne += numDaysNov; } if (monthOne == 12 ) { totalDayOne += numDaysDec; } if ( monthTwo == 1 ) { totalDayTwo += numDaysJanTwo; } if ( monthTwo == 2 ) { totalDayTwo += numDaysFebTwo; } if ( monthTwo == 3 ) { totalDayTwo += numDaysMarTwo; } if ( monthTwo == 4 ) { totalDayTwo += numDaysAprTwo; } If ( monthTwo == 5 ) { totalDayTwo += numDaysMayTwo; } if (monthTwo == 6 ) { totalDayTwo += numDaysJunTwo; } if ( monthTwo == 7 ) { totalDayTwo += numDaysJulTwo; } if ( monthTwo == 8 ) { totalDayTwo += numDaysAugTwo; } if ( monthTwo == 9 ) {
  • 6. totalDayTwo += numDaysSepTwo; } if ( monthTwo == 10 ) { totalDayTwo += numDaysOctTwo; } if (monthTwo == 11 ) { totalDayTwo += numDaysNovTwo; } if (monthTwo == 12 ) { totalDayTwo += numDaysDecTwo; } int daysBetween = totalDayOne – totalDayTwo; if ( totalDayOne < totalDayTwo ) { daysBetween = totalDayTwo – totalDayOne; } int daysTotal = 0; while ( yearOne < yearTwo ) { yearOne++; if ( yearOne % 4 == 0 && yearOne % 100 != 0 || yearOne % 400 == 0) daysTotal += 366; else daysTotal += 365; } while ( yearTwo < yearOne ) { yearTwo++; if ( yearTwo % 4 == 0 && yearTwo % 100 != 0 || yearTwo % 400 == 0) daysTotal += 366; else daysTotal += 365; } System.out.printf ( “ The total number of days between the dates is %d ”, daysTotal + daysBetween); } } Solution
  • 7. import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class NewDateDifference { public static void main(String[] args) { System.out.print("Insert first date : "); Scanner s = new Scanner(System.in); String[] eingabe1 = new String[3]; while (s.hasNext()) { int i = 0; insert1[i] = s.next(); if (!s.hasNext()) { s.close(); break; } i++; } System.out.print("Insert second date : "); Scanner t = new Scanner(System.in); String[] insert2 = new String[3]; while (t.hasNext()) { int i = 0; insert2[i] = t.next(); if (!t.hasNext()) { t.close(); break; } i++; } Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(insert1[0])); cal.set(Calendar.MONTH, Integer.parseInt(insert1[1])); cal.set(Calendar.YEAR, Integer.parseInt(insert1[2])); Date firstDate = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(insert2[0]));
  • 8. cal.set(Calendar.MONTH, Integer.parseInt(insert2[1])); cal.set(Calendar.YEAR, Integer.parseInt(insert2[2])); Date secondDate = cal.getTime(); long diff = secondDate.getTime() - firstDate.getTime(); System.out.println ("Days: " + diff / 1000 / 60 / 60 / 24); } }