How to reuse a variable without initializing a new one in for loop in java?

前端 未结 1 1951
轻奢々
轻奢々 2021-01-14 08:30

I was writing a function in java which counts the number of characters after white spaces in a string. This problem might sound trivial to some of you.

publ         


        
1条回答
  •  隐瞒了意图╮
    2021-01-14 09:15

    You don't need to declare a new variable:

    for (; position

    You can leave any field of the for loop blank.

    Or better yet, why not:

    count = a.length - position;
    

    0 讨论(0)
提交回复
热议问题