Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uni.fmi.bachelors;
- public class RunPingPong implements Runnable{
- String word;
- int time;
- public RunPingPong(String word, int time) {
- this.word=word;
- this.time=time;
- }
- @Override
- public void run() {
- for(int i=1; i<=5; i++){
- System.out.println(word);
- try{
- Thread.sleep(time);
- }catch (InterruptedException e){
- //to do auto genereted stub
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] args) {
- RunPingPong ping=new RunPingPong("Ping",100);
- RunPingPong pong=new RunPingPong("\tPong",100);
- Thread t1=new Thread(ping);
- Thread t2=new Thread(pong);
- t1.start();
- t2.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement