I'm new to java and i have written a code to print out the leap years between a certain range and for the output, i want to print out 3 leap years per line, with each year separated by commas.
For example, between the year 1999 to 2045, the output i want is:
2000,2004,2008
2012,2016,2020
2024,2028,2032
2036,2040,2044
I have written the code:
for (int year = 1999; year<2045; year ++) {
if (((year%4 == 0) && (year%100 !=0)) || (year%400==0)) {
System.out.println(String.format(format, year)); #issue here
}
}
I'm confused on how the String format works through the String.format notation that i plan to use when printing. Would appreciate some help on this.
String.formatwithinSystem.out.print...when you can justSystem.out.printf.formatworks - docs.oracle.com/javase/tutorial/java/data/numberformat.html