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
Get step-by-step solutions from verified subject matter experts
