Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.*;
  2. class StringGenerator extends Thread
  3. {
  4.  
  5.     char c[]=new char[5];
  6.     char a,b;
  7.     long id;
  8.     boolean signal=true;
  9.     public StringGenerator(char a,char b)
  10.     {
  11.  
  12.         this.a=a;this.b=b;
  13.         start();
  14.  
  15.     }
  16.     public void run()
  17.     {
  18.         id = Thread.currentThread().getId();
  19.         while(signal)
  20.         {
  21.             Random rnd = new Random();
  22.             for(int i=0;i<5;i++)
  23.             {
  24.             c[i]= (char) (rnd.nextInt(((int)b - (int) a) +1) + (int)'A');
  25.             }
  26.             System.out.println("nit " + id);
  27.             String s = "";
  28.             for(int i=0;i<5;i++) s+= c[i];
  29.             System.out.print(s);
  30.             System.out.println();
  31.             try{
  32.             Thread.sleep(1000);
  33.             }catch(InterruptedException n){}
  34.         }
  35.         System.out.println("Nit je zaustavljena");
  36.     }
  37.     public void zaustavi(){
  38.         signal=false;
  39.     }
  40.     public static void main(String args[])
  41.     {
  42.         StringGenerator n1=new StringGenerator('A','Z');
  43.         StringGenerator n2=new StringGenerator('M','N');
  44.         StringGenerator n3=new StringGenerator('A','z');
  45.         StringGenerator n4=new StringGenerator('B','F');
  46.         try{
  47.                     Thread.sleep(25000);
  48.             }catch(InterruptedException a){}
  49.             n1.zaustavi();
  50.             n2.zaustavi();
  51.             n3.zaustavi();
  52.             n4.zaustavi();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement