Friday 15 May 2015

java - For Loop: Leap year -



java - For Loop: Leap year -

i'm trying write programme displays 10 jump years per line until year 2100.

the code have far this:

public class leapyear { public static void main (string args[]){ int leapyear = 2001; // initialize leapyear variable 2001 if (leapyear <= 2100){ (int x = 0; x <= 10; x++){ // print 10 jump years per line system.out.print(leapyear + " "); leapyear = leapyear + 4; }// end of loop system.out.println(" "); int x = 0; } // end of if statement }// end of main method

}// end of class

the output code is:

2001 2005 2009 2013 2017 2021 2025 2029 2033 2037 2041

i'm having problem finding status allow me print next series of leapyears on next lines. guidance appreciate.

change if(leapyear <= 2100) line while(leapyear <= 2100).

the if statement execute once, meaning print out 10 dates. while loop execute many times takes leapyear greater 2100.

java if-statement for-loop

No comments:

Post a Comment