hawzze

PingPong-threads

May 17th, 2021
489
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package uni.fmi.bachelors;
  2.  
  3. public class PingPong  extends Thread{
  4.     String word;
  5.     int time;
  6.     public  PingPong (String word, int time){
  7.         this.word=word;
  8.         this.time=time;
  9.     }
  10.     public void run (){
  11.         for (int i=1; i<=5; i++){
  12.             System.out.println(word);
  13.             try{
  14.                 sleep(time);
  15.             }catch (InterruptedException e){
  16.                 //to do auto genereted catch block
  17.                 e.printStackTrace();
  18.             }
  19.         }
  20.     }
  21.  
  22.     public static void main(String[] args) {
  23.             new PingPong("Ping",100).start();
  24.         new PingPong("\tPong",100).start();
  25.  
  26.     }
  27. }
  28.  
RAW Paste Data