Advertisement
makispaiktis

Counting time with a clock 2

Mar 15th, 2020 (edited)
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 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.         int counter = 0;
  9.         for(int i=0; elapsedTime/1000F <= 5;){
  10.             long currentTime = System.currentTimeMillis();
  11.             elapsedTime = currentTime - startTime;
  12.             if(elapsedTime/1000F == (int)(elapsedTime/1000F)){
  13.                 counter++;
  14.                 System.out.println("Time: " + (int)(elapsedTime/1000F) + ", " + counter);
  15.             }
  16.         }
  17.     }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement