if(year % 400 == 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 if(year % 4 == 0){
System.out.println("Number of days in the year: " + 366);
}else{
System.out.println("Number of days in the year: " + 365);
}
my code works and everything passed but can anyone tell me how to optimize my codehidden #10366080
Level 5
this is a working code, but i need optimization
Under discussion
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Mohamad
18 November 2018, 10:35
this one will solve the problem
if ((year%400==0 || year%100!=0) &&(year%4==0)){
System.out.println("Number of days in the year: 366");
}
else{System.out.println("Number of days in the year: 365");}
+1
hidden #10366080
18 November 2018, 18:04
Thanks bruv
0
Sushant
14 August 2019, 04:16
thanks mohamad
0
Mohamad
18 November 2018, 10:33
((year%400==0 || year%100!=0) &&(year%4==0))
0
carolina
12 November 2018, 03:32
I'm new in this and I don´t know which one is better. but I show you my code, so you can compare:
if(x % 4 == 0 && (x % 100 != 0 || x % 400 == 0)){
x = 366;
System.out.println("Number of days in the year: " + x);
}else {
x = 365;
System.out.println("Number of days in the year: " + x);
}
+2
hidden #10366080
12 November 2018, 13:52
NIce!!! far more efficient. thanks buddy
+2