Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class StringGenerator extends Thread
- {
- char c[]=new char[5];
- char a,b;
- long id;
- boolean signal=true;
- public StringGenerator(char a,char b)
- {
- this.a=a;this.b=b;
- start();
- }
- public void run()
- {
- id = Thread.currentThread().getId();
- while(signal)
- {
- Random rnd = new Random();
- for(int i=0;i<5;i++)
- {
- c[i]= (char) (rnd.nextInt(((int)b - (int) a) +1) + (int)'A');
- }
- System.out.println("nit " + id);
- String s = "";
- for(int i=0;i<5;i++) s+= c[i];
- System.out.print(s);
- System.out.println();
- try{
- Thread.sleep(1000);
- }catch(InterruptedException n){}
- }
- System.out.println("Nit je zaustavljena");
- }
- public void zaustavi(){
- signal=false;
- }
- public static void main(String args[])
- {
- StringGenerator n1=new StringGenerator('A','Z');
- StringGenerator n2=new StringGenerator('M','N');
- StringGenerator n3=new StringGenerator('A','z');
- StringGenerator n4=new StringGenerator('B','F');
- try{
- Thread.sleep(25000);
- }catch(InterruptedException a){}
- n1.zaustavi();
- n2.zaustavi();
- n3.zaustavi();
- n4.zaustavi();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement