We know that January, March, May, July, August, October, and December have 31 days, while April, June, September, and November have 30 days. In the above code, month 1 means January, month 2 means February, and so on. In switch, if we don't have a break statement, a matching case falls through until it encounters a break statement, which will be printed with the exception of the default case. The else statement can either be a single statement, or it can even be a block of statements. If it is true, control goes to one block of code, and if it isn’t, then control goes to a different block of code defined in else. The if-else statement allows the programmer to do exactly that with their code. If not a leap year February, the answer is 28. If the month is a leap year, February, the answer is 29. If the month is either April, June, September, and November, the answer is 30. If the month is either of January, March, May, July, August, October, and December, the answer is 31. For example, let's consider a situation where we need to think about the number of days present in each month. In our day-to-day lives, we always decide on things by using if-else.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |