Answer to Question #46740 in Java | JSP | JSF for Kishore Kumar

Question #46740
java programme which will print the current time on the console every two seconds after doing this activity for 20 seconds the program quits.
1
Expert's answer
2014-09-24T12:20:45-0400
import java.util.Date;

public class PrintTime {

public static voidmain(String[] args) throws InterruptedException {
long start =System.currentTimeMillis();
while (true) {
Thread.sleep(2000);
System.out.println(new Date());
long finish =System.currentTimeMillis();
if (finish - start>= 20000) {
break;
}
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS