Sunday, 6 May 2018

How to print 1 to 100 without using loop

recursion call works the same as a loop.

/**
 *
 * @author YNZ
 */
public class PrintOneToNWithoutLoop {

    public static void main(String[] args) {
        printN(1);
        System.out.println("");
    }

    public static void printN(int n) {
        if (n <= 100) {
            System.out.print(" " + n);
            n++;
            printN(n);
        }

    }

}



No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...