Java - Write code to add day to Date

Requirements

Write code to add day to Date

Demo

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    public static void main(String[] argv){
        Date d = new Date();
        long day = 42;
        System.out.println(addDate(d,day));
    }// w  w w  . jav  a 2 s .  co m
    public static Date addDate(Date d, long day) throws ParseException {
        long time = d.getTime();
        day = day * 24 * 60 * 60 * 1000;
        time += day;
        return new Date(time);
    }
}

Related Exercise