开发者

Resetting counter to zero

开发者 https://www.devze.com 2023-01-21 12:16 出处:网络
I\'m currently learning Java. I have a for loop which uses a counter to keep track of how many words are written on a line.

I'm currently learning Java.

I have a for loop which uses a counter to keep track of how many words are written on a line.

When the wordCount == 10, I insert a line break System.out.println()

I want to reset开发者_JAVA技巧 wordCount to zero after this line break, but redeclaring wordCount == 0 is "not a statement" in NetBeans. How do I reset a variable value? Thanks


Try:

wordCount = 0;

Using the double equals sign == is comparison, while the single equals sign = is assignment.


Yeah u can add a condition :

if ( wordcount ==10) wordcount =0;

This will reinitialize wordcount to 0, when it becomes 10. Hope it helps.

We use '==' during comparison and '=' for assigning values.

0

精彩评论

暂无评论...
验证码 换一张
取 消