Number of days in the year

  • 8
  • Locked
On Earth, a year lasts 365 or 366 days. The number of days is calculated according to the following formula: A leap year (366 days) is every year evenly divisible by 4, except for years that are multiples of 100 but not multiples of 400. We'll write a program that will determine whether the user has entered a leap-year or ordinary year from the keyboard.
You can't complete this task, because you're not signed in.
Comments (33)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Daisy
Level 8 , San Jose
30 May 2021, 09:52
It can be solved without the operator % hint: when int a can be evenly divisible by int b, a==(a/b)*b.Then you can nail it with if/else!
ImDevin
Level 15 , Old Town, United States
29 March 2021, 21:37
Number of days in the year: x , where x is 366 for a leap year, and x is 365 for an ordinary year. all this means is they want you to hard-code the numbers in! I was putting a variable x and x++, thus failing the test over and over again! what a STUPID waste of time! :/
Seth Barker
Level 5 , Eureka Springs, United States
30 January 2021, 23:05
I created code to perform all the functions, however, I was leaving off the #4 task. The line of code that covered "all the remaining years"
Libby
Level 20 , United Kingdom
10 January 2021, 18:12
For some reason, the help section won't accept my question. Can anyone help me out here? The third requirement is not met. package com.codegym.task.task04.task0414; /* Number of days in the year */ import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String y = bufferedReader.readLine(); int a = Integer.parseInt(y); int leap400 = a % 400; int nonLeap = a % 100; int leap4 = a % 4; if (a == leap400) { System.out.println("Number of days in the year: 366"); } else if (a == nonLeap) { System.out.println("Number of days in the year: 365"); } else if (a == leap4) { System.out.println("Number of days in the year: 366"); } else { System.out.println("Number of days in the year: 365"); } } }
Roman
Level 41
11 January 2021, 07:02
You received the recommendation "Check the solution with different input values, for example: 1988"! Your solution says "Number of days in the year: 365" for 1988. But 1988 is a leap year and has 366 days!
Libby
Level 20 , United Kingdom
3 January 2021, 08:27
Third requirement not met. They don't allow me to post my question in the help section. It says "Invalid request argument"
Roman
Level 41
4 January 2021, 09:12
Please check if all fields are filled in when posting a question in the help section. If there is still an error, contact support.
Albert
Level 6 , Hong Kong, Hong Kong
20 November 2020, 03:18
// I skipped the task with frustration and returned with ease after learning "%"
Mihai Bone
Level 8 , Bucharest, Romania
30 September 2020, 00:56
I did waste 13 tries to get tis right.
Karas Java Developer
25 August 2020, 18:46
Every year that is evenly divisible by 4 is a leap year, unless they are evenly divisible by 100, in which case they also need to be evenly divisible by 400.
Richard Caputo
Level 16 , United States of America
3 September 2021, 21:40
This is exactly the math explanation I needed, thanks
Ivan
Level 9 , Uzhhorod, Ukraine
22 June 2020, 11:39
This Statement "if the year is evenly divisible by 400, then it is a leap year" is false coz 2004 / 400 = 5.01
punkuotukas
Level 7 , Vilnius, Lithuania
25 June 2020, 16:11
But it's still divisible by 4.
Ivan
Level 9 , Uzhhorod, Ukraine
25 June 2020, 16:29
I just didn't get conditions of the task at once)
Liew
Level 10
16 April 2020, 07:20
follow the steps from the hint it is very helpful.e.g. 4 steps then use 4 if else statements.