About
package endsem; import java.awt.print.Printable; import java.util.*;
public class random {
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer x =14;
first task= new first(x);
Thread t1=new Thread(task);
t1.start();
try{
t1.join();
System.out.println(task.getval());
}
catch(Exception e){
System.out.println("Exception");
}
}
}
class first implements Runnable{
private static Integer a = null;
private static Integer b = null;
first(Integer a){
a=this.a;
}
@Override
public void run() {
// TODO Auto-generated method stub
if(a%7==0){
second task1= new second(a);
Thread t2=new Thread(task1);
t2.start();
try{
t2.sleep(5000);
t2.join();
b=task1.getval();
}
catch(Exception e){
System.out.println("Exception");
}
}
else{
third task2= new third(a);
Thread t3=new Thread(task2);
t3.start();
try{
t3.sleep(5000);
t3.join();
b=task2.getval();
}
catch(Exception e){
System.out.println("Exception");
}
}
}
public int getval(){
return b;
}
}
class second implements Runnable{
private static Integer a = null;
second(Integer a){
a=this.a;
}
public void run(){
a=2*a;
}
public int getval(){
return a;
}
}
class third implements Runnable{
private static Integer a = null;
third(Integer a){
a=this.a;
}
public void run(){
a= 3*a;
}
public int getval(){
return a;
}
}