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++; }

Answers

Answer 1

Answer:

The correct code to the given question is

if ((counter % 10) == 0)  // check the condition

{

System.out.println("Counter is divisible by ten: " + counter);  // display

}

else  // check the condition

{

System.out.println("Counter is not divisible by ten: "  +counter); // display the //value

}

counter++; // increment the value of counter

Explanation:

Following are the description of code

In the given question we have to check the condition that the given number is divisible by 10 or not .In the if block if the number is divisible by 10 then it print the value of number and increment the value of counter .In the else block if the number is not divisible by 10 then it print the value of number and increment the value of counter .It means the value of counter is increases in the if block as well as in the else block .So we have to remove the counter statement from there and place outside the if and else block .


Related Questions

Other Questions
The formation of the House of Burgesses was based on what?A) the business practices of the Virginia Company. B) the political rights of the English. C) the shareholders rights in a joint-stock company. D) the colonists relationship with the Powhatan. Will give brainliest, someone please help PLEASE HURRY Find the measures of the numbered angle Zuckermans test for sensation seeking measures which of the following characteristics?dangerousness, antisocial traits, letting loose, and intolerance for boredomthrill and adventure seeking, experience seeking, disinhibition, and susceptibility to boredomadventurousness, physical prowess, creative morality, and charismadangerousness, adventurousness, creativity, and thrill and adventure seeking The terminal window wants to evaluate your current bash knowledge by using the ~/workspace/nested-directories folder: a. cd into the nested-directories/nested-level-1/ directory by using an absolute path b. cd into the nested-level-3/ directory by using a relative path d. Move the entire ~/workspace/config/ directory to the nested-level-1/ directory Which of these viral cytopathic effects is most likely to be associated with the development of cancer? To plot the point (5, -3) you would move up 5, then left 3.TrueFalse The mass of Box A and Box B is 0.6 kg. The mass of Box A and Box C is 1.3 kg.Box C is 3 times as heavy as Box B. Find the mass of Box A. how to do this question plz PLEASE HELP - Find the area of a regular octagon with a side length of 5 cm. Round to the nearest tenth. (Please explain in full detail the process, im trying to learn how to do these) thank you!! help help help pls pls Find the value of y. Jennifer had $80 to spend on herself. She spent 1/5 of the money on a sandwhich, 1/6 for a ticket to a museum, and 1/2 of it on a book. How much money does Jennifer have left over? Give three reasons why you think the author uses Death as the narrator in the book "The Book Thief" Read and choose the option with the correct sentence that matches the image.O El garaje est debajo del balcn.O El balcn est detrs del garaje.El garaje est dentro del balcn.O El balcn est enfrente del garaje. If $\sqrt{5+n}=7$, then what is the value of $n$? A school contains 357 boys and 323 girls.If a student is chosen at random, what is the probability that is a girl?Correct your answer to 2 decimal places. In which quadrants do solutions for the inequality y is less than or equal to two sevenths times x plus 1 exist? A large company is accused of gender discrimination in wages. The following model has been estimated from the company's human resource information. In (WAGE) = 1.439 + .0834 EDU + .0512 EXPER + .1932 MALE Where WAGE is hourly wage, EDU is years of education. EXPER is years of relevant experience, and MALE indicates the employee is male How much more do men at the firm earn, on average? a) $1.21 per hour more than females b) 19.32% more than females c) $19.32 per hour d) $19, 320 more per year than females^2 Cass is walking her dog (Oreo) around the neighborhood. Upon arriving at Calina's house (a friend of Oreo's), Oreo turns part mule and refuses to continue on the walk. Cass yanks on the chain with a 67 N force at an angle of 30 above the horizontal. Determine the horizontal and vertical components of the tension force.