when i'm trying to validate my code i get error message the fourth condition is not meet.
Here my code:
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
Scanner read = new Scanner(System.in);
int year;
year = read.nextInt();
if((year%400)==0 && (year%100)==0){
System.out.println("Number of days in the year: "+366);
} else if((year%4)==0){
System.out.println("Number of days in the year: "+366);
} else if ((year%100)== 0 && (year%400)!=0){
System.out.println("Number of days in the year: "+365);
} else {
System.out.println("Number of days in the year: "+365);
}
}
}
help needed
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
klesk
4 January 2020, 22:17
Try to rotate the first and the second "else if block", because if (year%4)==0 is true, the next expression (year%100)==0 isn't checked anymore. Also the first expression ((year%400)==0 && (year%100)==0) is a little to much, because if it is divisible through 400 it is also divisible through 100. You can remove (year%400)!=0 because all numbers meet this requirement because of the first if block.
0