Question: In Java please. This problem can be done in main. Apply the increment operator (++) 10 million times, first to an Integer reference and then

In Java please.

This problem can be done in main. Apply the increment operator (++) 10 million times, first to an Integer reference and then to a variable of type int, each set initially to 1. Compare the running times.

To compare running times we use the method long System.currentTimeMillis()

that returns the current time in milliseconds.

For both the Integer reference x and the primitive y, the main method

  • records the starting time in milliseconds,
  • increments with ++ a variable 10,000,000 times,
  • records the ending time in milliseconds, and
  • displays the elapsed time, ending time - starting time.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!