简体   繁体   中英

Resetting counter to zero

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM