Advertisement
makispaiktis

Counting time with a clock

Mar 15th, 2020 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. public class Clock {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.         long startTime = System.currentTimeMillis();
  6.         System.out.println(startTime);
  7.         long elapsedTime = 0;
  8.         for(int i=0; elapsedTime/1000F <= 5;){
  9.             long currentTime = System.currentTimeMillis();
  10.             elapsedTime = currentTime - startTime;
  11.             if(elapsedTime/1000F == (int)(elapsedTime/1000F)){
  12.                 System.out.println("Time: " + (elapsedTime/1000F));
  13.             }
  14.         }
  15.     }
  16.  
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement