# leap year java using while and do-while loop

Page 1 of 1

## 7 Replies - 8739 Views - Last Post: 07 September 2011 - 06:06 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=246285&amp;s=e1ac4166caa441480bacc9b7a8fe255f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hatredforyou

Reputation: 0
• Posts: 9
• Joined: 07-September 11

# leap year java using while and do-while loop

Posted 07 September 2011 - 04:23 AM

hi guys can u help me with my program about the leap year using whule and do while loops?

it must display the leap year from 1900 to 2100. A year is a leap year if it divisible by 4.But if the year is divisible by 100 then it is not a leap year, unless divisible by 400.
Is This A Good Question/Topic? 0

## Replies To: leap year java using while and do-while loop

### #2 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 04:47 AM

And what have you tried, what you want to loop to. Looks like you will loop from 1900 to 2100, then for each number find if it is divisible by those numbers or not, so if leap display it, else skip it.

### #3 hatredforyou

Reputation: 0
• Posts: 9
• Joined: 07-September 11

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 04:52 AM

smohd, on 07 September 2011 - 04:47 AM, said:

And what have you tried, what you want to loop to. Looks like you will loop from 1900 to 2100, then for each number find if it is divisible by those numbers or not, so if leap display it, else skip it.

will what i want in the program is that it must show the syntax of while and do-while loop.

so was wondering how to do it?

### #4 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 05:13 AM

You will have a while loop in it that will continue to loop while year is less than 2100, then in it you will have the code to check if a year is leap or not, example:
``` int year = 1900;
while(year <= 2100)
//now here check if it is leap or not
// try putting the conditions pbl show in the link above
// then if it is display as a leap
// else skip it and get to the next year
year++;
}//end while
```

Try to try doing it and tell us where you get stack so we can continue helping. We like to see your effort rather than giving the full running code for you. Try it and you can figure out :

### #5 hatredforyou

Reputation: 0
• Posts: 9
• Joined: 07-September 11

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 05:32 AM

smohd, on 07 September 2011 - 05:13 AM, said:

You will have a while loop in it that will continue to loop while year is less than 2100, then in it you will have the code to check if a year is leap or not, example:
``` int year = 1900;
while(year <= 2100)
//now here check if it is leap or not
// try putting the conditions pbl show in the link above
// then if it is display as a leap
// else skip it and get to the next year
year++;
}//end while
```

Try to try doing it and tell us where you get stack so we can continue helping. We like to see your effort rather than giving the full running code for you. Try it and you can figure out :

i tried what u said..and its running..

it just loops back to 1900.

### #6 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 05:36 AM

Can we see what you have tried? Post your code in code tags like and tell us what problem/error is happening... Also what do you you mean by loops back to 1900?

### #7 hatredforyou

Reputation: 0
• Posts: 9
• Joined: 07-September 11

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 05:43 AM

smohd, on 07 September 2011 - 05:36 AM, said:

Can we see what you have tried? Post your code in code tags like and tell us what problem/error is happening... Also what do you you mean by loops back to 1900?

lemme finish it up..i think i got it..

just 1 more question..

on the part where u said "//here check if it is leap or not"

how do u check it?i mean what do u do?the rest i think i understand what to do..

### #8 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: leap year java using while and do-while loop

Posted 07 September 2011 - 06:06 AM

You check if the year is divisible by 4 using modulus(%), if yes then check if it divisible by 100, if yes then it must be divisible by 400 also as what you said. Like:
``` if (year % 4 == 0){
if(year % 400 == 0)
//is leap
else
if(year %100 == 0)
//no leap
}
else
// not leap
```
like so