CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    2

    My little Java Problem Please HELP!

    I am trying to write a program for school that prompts the user for a year (ie. 1980) and then determines if the date in question is a leap year or not. I am told that it is a leap year if the year is divisible by 4 or 400. It is not if it is divisible by 100. I have created double variables that hold the values of year /400, year /40, year / 100. I am thinking of using a "if else" statement however I am stumped as too how to make the program decided if it is a leap year or not. If anyone out there can shed some light on this I would very much appreciate it. I have spent quite some time on this problem and I just want to move on. I am sure it is a simple solution and I am just not seeing it.



  2. #2
    Join Date
    Apr 2000
    Location
    NJ
    Posts
    123

    Re: My little Java Problem Please HELP!

    if you have a year value in a varible
    try something like this use the modulous operator.
    This operator will help you determine if a a value is even divisible by another

    double val1 = 100;
    boolean isLeap;
    double year =1995.0;
    if(year % val1 != 0) //not evenly divisible
    isLeap=true;



    While I dont think this alone will determine if you hava a leap year you can caunduct any of your tests in this way and then set your boolean variable accordingly

    52901368

  3. #3
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    2

    Re: My little Java Problem Please HELP!

    Thanks for your prompt reply. I was able to properly code my final application and I submitted it just as lecture was ending. Man that's too close for my comfort. I tested it and it works, I didn't use a boolean operator however. I just used the modulous character when calculating whether or not my year variable (which is the user inputed year) is divisible evenly by 4 or 400. I then used an if else loop to test to see is my variable was greater than 0 and if it was then it printed something , and if it wasn't it did something else.
    Thanks again for the prompt response without it I would not have gotten my assignment in on time and would have been stuck with a zero.I currently have an A in this class so I was a tad stressed.
    Thanks.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured