I also would like any help with this program. I'm supposed to be able to pick between two years and the program should count how many days were passed or are in between the two years. (i.e.--Years: ((7 4 1776) & (1 1 1987)); Answer: 76882 days.
import java.util.*;
public class DiffinDates
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
int m; //month
int d; //day
int y; //year
boolean leapYear; //to check if it's a leap year
int daysInMonth; //if leap year, either 28 or if not leap year, 29
long r; //result
System.out.println("Please type in your dates using 'mm dd yyyy' numbers only: ");
System.out.print("M: ");
m = scan.nextInt();
System.out.print("D: ");
d = scan.nextInt();
System.out.print("Y: ");
y = scan.nextInt();
System.out.print("M: ");
m = scan.nextInt();
System.out.print("D: ");
d = scan.nextInt();
System.out.print("Y: ");
y = scan.nextInt();
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
daysInMonth = 31;
}
else if(m==4||m==6||m==9||m==11)
{
daysInMonth = 30;
}
else
{
m = 2;
}
if(y % 400 == 0)
{
leapYear = true;
}
else if((y % 4 == 0) && (y % 100 != 0))
{
leapYear = true;
}
else
{
leapYear = false;
}
if(leapYear)
{
daysInMonth = 29;
}
else
{
daysInMonth = 28;
}
r = (m + d + y + daysInMonth)
System.out.println("Data: " + m + " " + d + " " + y)
System.out.println("The total days between your years picked are: " + result);
System.out.println("This program was written by Mssbrightside25.");
}
}
This post has been edited by mssbrightside25: 02 July 2009 - 01:47 PM

New Topic/Question
Reply



MultiQuote




|