import java.util.Scanner; public class Tradklokke { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Trykk enter for aa starte..."); scan.nextLine(); Thread t1 = new Thread(new Stoppeklokke()); t1.start(); System.out.println("Trykk enter for aa avslutte..."); scan.nextLine(); t1.interrupt(); System.out.println("Avsluttet"); scan.close(); } } class Stoppeklokke implements Runnable { public void run() { int counter = 0; while(true) { try { Thread.sleep(1000); System.out.println(counter); counter++; } catch(InterruptedException e) { System.out.println("Interrupted!"); return; } } } }