Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use TimeUnit in java

I am trying to use TimeUnit in java but it just send me errors That’s how I wrote it

import java.util.concurrent.TimeUnit ;

public class Anything { 
    public static void main( String[] args ) {
        System.out.println("hi");
        TimeUnit.SECONDS.sleep(6);
        System.out.println("hi");
    }
}
like image 975
Ibraheem Alyan Avatar asked Mar 08 '23 09:03

Ibraheem Alyan


1 Answers

Try this as your code have many syntax errors as well as you are not handling Exception during the call of TimeUnit.SECONDS.sleep(6);, either use throws or surround this with try catch.

import java.util.concurrent.TimeUnit ;

public class Anything { 
    public static void main( String[] args ) throws InterruptedException {
        System.out.println("hi");
        TimeUnit.SECONDS.sleep(6);
        System.out.println("hi");
    }
}
like image 115
Lalit Verma Avatar answered Mar 14 '23 22:03

Lalit Verma