Q:

Java program to get elapsed time in seconds and milliseconds

0

Java program to get elapsed time in seconds and milliseconds

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Get elapsed time by a program in Java

//Java program to get elapsed time in seconds and milliseconds.
 
import java.util.Scanner;
 
public class ElapsedTime 
{
 
    public static void main(String[] args) 
    {
        long startTime; //start time
        long endTime;   //end time
        double time;    //time difference
         
        startTime = System.currentTimeMillis();
 
        //doing some operation
        //read and print your name      
        System.out.print("Enter you name: ");
        //Scanner class object
        Scanner SC=new Scanner(System.in);
        String name=SC.nextLine();
         
        System.out.println("Thanks "+ name +" ! ");
 
        endTime = System.currentTimeMillis();
        time = (endTime - startTime) / 1000.0;
 
        System.out.println("\nElapsed Time is:  " + time);
    }
 
}

Output

    
    Enter you name: Alexender
    Thanks Alexender ! 

    Elapsed Time is:  3.452

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Core Java Example programs for Beginners and Professionals

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to count divisors of an integer numbe... >>
<< Java program to print table of an integer number...