-1

I have worked on a loan installment calculator in Java swing. How do I get 6 month dates if I make 6 month installments. I want this scenario in Java swing. How do I get 6, 8, 10 month dates in loop in Java swing?

enter image description here

for (int i = 0; i < date.length; i++) { // cycle #1: over all initialized dates
    for (int j = 0; j < 40; i++) {      // cycle #2: 40 repeats for each date
        date[i].nextDay();
        System.out.print("Incremented Date:" + date[i].toString());
    }
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • 1
    Welcome Naveed. Have you consider google **java calendar add month** ? – TungstenX Feb 15 '19 at 07:33
  • 1
    Question is not clear for me. What is this 40? What are the objects you use in `date` array? `java.util.Date` objects? – Prasad Karunagoda Feb 15 '19 at 13:32
  • I suggest you stay away from `java.util.Calendar` and `java.util.Date`. They are **old**. Look into `LocalDate` and perhaps `YearMonth` of [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Feb 15 '19 at 19:50
  • Possible near-duplicate of [How to iterate through range of Dates in Java?](https://stackoverflow.com/questions/4534924/how-to-iterate-through-range-of-dates-in-java). Just like `LocalDate` has a `plusDays` method used in some of the answers there it also has a `plusMonths` method that you may use to your advantage. – Ole V.V. Feb 15 '19 at 19:56

1 Answers1

1

It’s not really clear to me, but you may mean something like the following?

    LocalDate startDate = LocalDate.of(2019, Month.FEBRUARY, 1);
    int months = 10;

    LocalDate currentDate = startDate;
    for (int i = 0; i < months; i++) {
        System.out.println(currentDate);
        currentDate = currentDate.plusMonths(1);
    }

Output:

2019-02-01
2019-03-01
2019-04-01
2019-05-01
2019-06-01
2019-07-01
2019-08-01
2019-09-01
2019-10-01
2019-11-01
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • Yes!, i want to make student installment plane for exmple if a student semster fee is 20000K and he want to make installment in 6 months , 20K installment for he make 5 installments then how we are genrate date with installments like 1st 01/02/2019, 2nd 01/02/2019 and so on 5.. – Naveed Islam Feb 16 '19 at 06:46