56.4k views
3 votes
What is the best way to improve the following code fragment? if ((counter % 10) == 0) { System.out.println("Counter is divisible by ten: " + counter); counter++; } else { System.out.println("Counter is not divisible by ten: " + counter); counter++; } Move the duplicated code outside of the if statement Shorten variable names Move the brackets to save several lines of code Add semicolons after the if condition and the else reserved word

User Dlchet
by
6.4k points

1 Answer

3 votes

Answer:

Move the duplicated code outside of the if statement

User Zan RAKOTO
by
6.3k points