Java中的倒计时后打印

Java中的倒计时后打印,java,timer,Java,Timer,我想在倒计时后打印。我已经在倒计时前打印过了,但我现在需要在倒计时后打印。我试着在很多地方使用它,但我不知道在哪里放置System.out.println(加法);这是方程的总值。 谢谢 Here's the code import java.util.Timer; import java.util.TimerTask; public class S1p4 { public static void main(String[] args) {

我想在倒计时后打印。我已经在倒计时前打印过了,但我现在需要在倒计时后打印。我试着在很多地方使用它,但我不知道在哪里放置System.out.println(加法);这是方程的总值。 谢谢

 Here's the code 

     import java.util.Timer; 
     import java.util.TimerTask;  
     public class S1p4 { 

     public static void main(String[] args) { 
     Timer timer = new Timer(); 
     Task task = new Task(); 
     timer.schedule(task, 1000, 1000); 

     int num1 = (int) (Math.random()*10); 

     int num2 = (int) (Math.random()*10); 

     int addition = (int) num1 + num2; 

     System.out.println (num1); 

     System.out.println("+"); 

     System.out.println (num2); 


     } 
     } 

     class Task extends TimerTask { 

     int i=4; 
     @Override 
     public void run() { 
     i--; 
     if(i==3) 
     System.out.println("3>>>"); 
     if(i==2){ 
     System.out.println("2>>>"); 
     } 
     if(i==1){ 
     System.out.println("1>>>"); 
     cancel(); 

     System.exit(0); 
     } 

     } 

     } 

我想你想做这样的事。请注意,我将结果添加到
任务的构造函数中,并在退出之前添加了
System.out.println

import java.util.Timer;
import java.util.TimerTask;

public class S1p4 {

  public static void main(String[] args) {
    Timer timer = new Timer();
    int num1 = (int) (Math.random() * 10);
    int num2 = (int) (Math.random() * 10);
    int addition = (int) num1 + num2;
    System.out.println(num1);
    System.out.println("+");
    System.out.println(num2);
    // Add the result to the task.
    Task task = new Task(addition);
    timer.schedule(task, 1000, 1000);
  }
}

class Task extends TimerTask {
  // Store the result.
  private int result;

  // Construct a Task with the result.
  public Task(int result) {
    super();
    this.result = result;
  }

  // How many times to run.
  int i = 4;

  @Override
  public void run() {
    i--;
    if (i == 3) {
      System.out.println("3>>>");
    } else if (i == 2) {
      System.out.println("2>>>");
    } else {
      System.out.println("1>>>");
      cancel();
      // The timer is done print the result.
      System.out.println("The result was " + result);
      System.exit(0);
    }
  }
}

请正确缩进代码。