In this section, you will study how to obtain the elapsed time. As you all know that the Elapsed time is the time taken to complete the process. In the given example, we have used the method System.nanoTime() to get the start time and the end time of the defined process. Here we are calculating the sum of first ten natural numbers in order to find the elapsed time by subtracting the start time from the end time of the process.
Here is the code of GetElapsedTime.java
Output will be displayed as:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.