1 Replies - 1600 Views - Last Post: 10 November 2008 - 04:10 PM Rate Topic: -----

#1 Jessman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-November 08

Can someone Help me with my Java homework?

Posted 10 November 2008 - 04:02 PM

Can someone help me with my Java homework?

Love the site BTW, gonna post here for quite a long time. :)

The task is:

Write an application that will accept an intreger from the user that represents a year. Use the MODULUS operator ( % ) to determine if the year is divisible by 4. Print an appropriate message and how many years to the next leap year.

Use a while loop to repeat until the user enters a year of 99.

Reject non-integer input.

I use Crimson Editor, This homework is driving me nuts, i am so confused >.<.

I did this and realised it was C++... I can't remember a thing!
nt year = 0;
cout << "enter 99 to end program" << endl;
while(year != 99)
{
cout << message here << endl;
cin >> year;
leap = year % 4;
if (leap = 0)
{
cout << "Next leap year etc" << endl;
}
else if(leap != 0)
{;
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Can someone Help me with my Java homework?

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Can someone Help me with my Java homework?

Posted 10 November 2008 - 04:10 PM

Actually you need to make further calculations to find out if the year is a leapyear. (There are other constraints)

if the year is divisible by 100, (year % 100 == 0) then it's not a leapyear.
unless of course the year is divisible by 400.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1