Calculate the amount of savings I will have in n months I have the following problem and I am new in Java:
I have an initial capital of 10 000. I invest this initial capital of 10 000 in the bank for a interest rate per month of 0.04/12. My net income is 3000 per month and my expenses per month is 2000. I invest also my monthysavings = net income - expenses = 3000 - 2000 = 1000 in the bank for the interest rate of 0.04/12.
I would like to calculate the amount of savings I will have in 300 months.
I did the following code:

public class RetCalcJava {


public double futureCapital(
      double interestRate
    , int nbOfMonths
    , int netIncome
    , int currentExpenses
    , double initialCapital) {


double  monthlySavings = netIncome - currentExpenses;
double iniVal=0;
double finalVal =0;
double intermediate = 0;

for (int i=0; i&lt; nbOfMonths; i++){
    System.out.println(&quot;Boucle&quot; + i);

    if (i ==0) {
        iniVal = initialCapital * (1 + interestRate) + monthlySavings;
        intermediate = iniVal;

        System.out.println(&quot;intival&quot; + iniVal);
    }
    else {
        finalVal =  intermediate * (1 + interestRate) + monthlySavings;
        intermediate = finalVal;
        System.out.println(&quot;finalVal&quot; + finalVal);
    } }    return finalVal;   

}
}

The main class is :
public class RetCalcMain {

public static void main(String[] args) {
    RetCalcJava retcal = new RetCalcJava();    
    retcal.futureCapital(0.04/12, 300, 3000,2000,10000);


    }
}

This code works. What do you think about my code? Is it optimized? What should I change?
Welcome to Code Review. Few suggestions:

Formatting: the code should be formatted to make it easier to read. Many IDEs support auto-formatting, or you can use an online formatter.
Naming: the class name RetCalcJava shouldn't include Java as suffix, the extension .java already tells what type of file is. It's also hard to understand what a class called RetCalc does, consider a more meaningful name. I am not sure what Boucle means.
Typo and spacing: iniVal, println(&quot;intival&quot; + iniVal). There are some typos and the result of the print is &quot;intival1000&quot;, it needs a space.
Static method: The method futureCapital does not need to use instance variables, so it can be static. By making it static we don't need to instantiate the class.
Formatting the output: the capital can be formatted as 541,267.20 instead of 541267.1989622512 using System.out.printf and %,.2f.
Accumulation:
iniVal = initialCapital * (1 + interestRate) + monthlySavings;
intermediate = iniVal;
System.out.println(&quot;intival&quot; + iniVal);
for (int i = 1; i &lt; nbOfMonths; i++) {
    //...
    finalVal = intermediate * (1 + interestRate) + monthlySavings;
    intermediate = finalVal;
    // ...
}
return finalVal;

The temporary variables intermediate and initVal are not necessary, see the code below.

Revised code
public class RetCalc {
    public static double futureCapital(double interestRate, int months, int netIncome, int currentExpenses,
            double initialCapital) {
        double monthlySavings = netIncome - currentExpenses;
        double capital = initialCapital;
        for (int i = 0; i &lt; months; i++) {
            capital = capital * (1 + interestRate) + monthlySavings;
            if (i == 0) {
                System.out.printf(&quot;Initial value: %,.2f%n&quot;, capital);
            } else {
                System.out.printf(&quot;Month: %d Capital: %,.2f%n&quot;, i + 1, capital);
            }
        }
        return capital;
    }

    public static void main(String[] args) {
        double futureCapital = RetCalc.futureCapital(0.04 / 12, 300, 3000, 2000, 10000);
        System.out.printf(&quot;Future capital: %,.2f%n&quot;, futureCapital);
    }
}

Output:
Initial value: 11,033.33
Month: 2 Capital: 12,070.11
...
Month: 300 Capital: 541,267.20
Future capital: 541,267.20