In this example we will show the method to add months in Java.
Source Code
package com.beginner.examples;
import java.util.Calendar;
public class AddMonths {
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.MONTH));
//months add 1
c.add(Calendar.MONTH, 1);
System.out.println(c.get(Calendar.MONTH));
}
}
Output:
6
7
References
Imported packages in Java documentation: