user339946
user339946

Reputation: 6119

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

Upvotes: 2

Views: 16670

Answers (2)

sethu
sethu

Reputation: 1721

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.

Upvotes: 3

Greg Hewgill
Greg Hewgill

Reputation: 994867

Try:

wordCount = 0;

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

Upvotes: 5

Related Questions