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?

有帮助吗?

解决方案

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));

其他提示

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));
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top