简体   繁体   English

java 延迟不工作,请帮助,谢谢:^) [暂停]

[英]Delay in java not working, help please and thank you :^) [on hold]

I'm trying to delay for a few seconds but all the things I searched up didn't work.我试图延迟几秒钟,但我搜索的所有东西都不起作用。 Can you guys help me?你们能帮帮我吗? EDIT: FIXED!!!编辑:已修复!!!

import java.util.Scanner;
import java.util.Date;
import java.util.concurrent.TimeUnit;
class Main {
  public static void main(String[] args) {
    System.out.println(" ");   
    System.out.println("WELCOME TO ANTARCTICA");
    TimeUnit.SECONDS.sleep(1);
    //////////////////
    System.out.println("You are a scientist and is currently researching polar bears in Antarctica. You want to see their contrast between predator-like abilities and passiveness.");

Your code looks right except handling the InterruptedException Try this:您的代码看起来正确,除了处理InterruptedException试试这个:

public static void main(String[] args) throws InterruptedException {
   //...
   TimeUnit.SECONDS.sleep(1);
   //...
}

Or this:或这个:

public static void main(String[] args) {
// ...
   try {
      TimeUnit.SECONDS.sleep(1);
   } catch (InterruptedException e) {
      e.printStackTrace();
   }
// ...
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM