code to print leap years between 1801 and 1900 using Java -
i trying write code outputs leap years between 1801 , 1900 , formatting output in lines of 10 years per each line.so far here have got
for(int 1 == 1800; <1900; i++200 ){ if (i % 100 !=0 || i% 400 == 0 ) system.out.printf("%4d %n" + i);
but giving me compilation errors.how can make sure code compiles without errors???
you need declare i
, , want increment i
one. need comma , printf
, algorithm needs test % 4 == 0
. like
public static void main(string[] args) { (int = 1800; < 1900; i++) { if ((i % 4 == 0 && % 100 != 0) || % 400 == 0) { system.out.printf("%4d%n", i); } } }
update
the output correct not formatting way want in lines of 10 leap years each.
then modiy print like
int count = 0; (int = 1800; < 1900; i++) { if ((i % 4 == 0 && % 100 != 0) || % 400 == 0) { system.out.printf("%d ", i); count++; if (count % 10 == 0) { system.out.println(); } } }
Comments
Post a Comment