Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Calendar;

public class Main {

    public static void main(String[] args) {

        Calendar cal = Calendar.getInstance();

        // display the current calendar
        System.out.println("Month is " + cal.get(Calendar.MONTH));

        // roll month
        cal.roll(Calendar.MONTH, 2);

        // print result after rolling
        System.out.println("Month is " + cal.get(Calendar.MONTH));

        // roll downwards
        cal.roll(Calendar.MONTH, -4);

        // print result
        System.out.println("Month is " + cal.get(Calendar.MONTH));
    }
}