Question

I need to rename photos to format photo01, photo02, photo03 ... photo 99 I'm using String.Format

for (int i = 0; i < 99; i++) {


        Log.d("format", String.format("photo%02d", i++));
    }

But i have only even nubmers: photo02 photo04 ..photo18 Why? And how i can get photo01, photo99 result?

Was it helpful?

Solution

You're incrementing i twice: once in the loop:

for (int i = 0; i < 99; i++) {

and once inside the loop:

Log.d("format", String.format("photo%02d", i++));

It should be

Log.d("format", String.format("photo%02d", i + 1));

OTHER TIPS

Remove i++ in the String.format and start the loop with 1 instead of 0

for (int i = 1; i <= 99; i++) {
    Log.d("format", String.format("photo%02d", i));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top