Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- AN an= new AN(false);
- Thread t1=new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- an.Alpha();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- Thread t2= new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- an.numbers();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- t1.start();
- t2.start();
- }
- boolean flag;
- AN(boolean flag)
- {
- this.flag=flag;
- }
- synchronized void Alpha() throws InterruptedException
- {
- if(flag==false)
- {
- for(char i='A'; i<='Z';i++)
- {
- System.out.println(+i);
- notifyAll();
- flag=true;
- }
- }
- else
- {
- wait();
- }
- }
- synchronized void numbers() throws InterruptedException
- {
- if(flag==true)
- {
- for(int i=1;i<=26;i++)
- {
- System.out.println(+i);
- notifyAll();
- flag=false;
- }
- }
- else
- {
- wait();
- }
- }
Add Comment
Please, Sign In to add comment