'How to add a number to variable within String.format?

I want output like:

Dividend 1 : ...
Dividend 2 : ...
Dividend 3 : ...

Here is my code:

int i = 0;
while(i < dividendRates.length) {
    System.out.println(String.format("Dividend %d : ", i) + (income * dividendRates[i]) );
    i = i + 1;
}

But dividend number start with 0.

The easy way is just create new variable like 'int e = 1;' and use it, but I want to use variable 'i' and have output start with 1.

What should I do?



Solution 1:[1]

You can try the following code and I hope get the point:

int i = 1;
    while( (i-1) < dividendRates.length) {
        System.out.println(String.format("Dividend %d : ", i) + (income*dividendRates[i]) );
        i = i + 1;

    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Software Tester at ExpandCart