Nora Hamad

Nora Hamad @nora_hamad

عضوة جديدة

public class CounterThread extends Thread { private int count; public CounterThread(int count) { this.count = count; } @Override public void run() { for (int i = 1; i <= count; i++) { System.out.println(i); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Thread interrupted: " + e.getMessage()); } } System.out.println("Counter finished."); } public static void main(String args) { CounterThread counterThread = new CounterThread(10); counterThread.start(); try { counterThread.join(); } catch (InterruptedException e) { System.out.println("Main thread interrupted: " + e.getMessage()); } System.out.println("Main thread finishes execution."); }}
0
30

يلزم عليك تسجيل الدخول أولًا لكتابة تعليق.

تسجيل دخول

خليك أول من تشارك برأيها   💁🏻‍♀️