John Squirrels told me that I have to leave my question here, so I'm doing that:
Hi. I think something is wrong in
https://codegym.cc/quests/lectures/questsyntax.level04.lecture04
because I've tried a lot of possibilities and never failed. But when I want to verify, an apparent error happen.
These are the messages:
OK - The program should read a number from the keyboard.
OK - The program should display text on the screen according to the task conditions.
NOT OK - If the entered year is a leap year, you should display: "Number of days in the year: 366".
RECOMMENDATION FROM YOUR MENTOR
Check the solution with different input values, for example: 1988
OK - If the entered year is not a leap year, you should display: "Number of days in the year: 365".
This is my code:
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 reader = new BufferedReader(new InputStreamReader(System.in));
String sNumero = reader.readLine();
int nNumero = Integer.parseInt(sNumero);
int entero1 = nNumero/4;
int entero2 = nNumero/400;
/*
System.out.println(entero1);
System.out.println(entero2);
System.out.println(entero1*4);
System.out.println(entero2*400);
*/
if (entero1*4 == nNumero && entero2*400 == nNumero )
System.out.println("Number of days in the year: " + 366);
else
System.out.println("Number of days in the year: " + 365);
I think something is wrong
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Ankush Rajput
3 October 2018, 03:29
Consider this part of your code -
&& means you have to satisfy both conditions.
Now consider 1988 as input. It is divisible by 4 but not by 400 and hence if statement will not executed whereas it should be executed as 1988 is a leap year.
Your code logic should be -
Think about it an rectify it.
+1
MARIO
4 October 2018, 01:27
Thank you. You are right.
I 've considered this part of the conditions:
"A leap year is every fourth year, except for years that are not a multiple of 400."
But the definition of a leap year say:
"Leap year is divisible by 4, unless it is the secular year of each century, ending in «00» -, in which case it must also be divisible by 400."
0