Skip to content

Instantly share code, notes, and snippets.

@Arjun2002tiwari
Created December 14, 2021 19:10
Show Gist options
  • Save Arjun2002tiwari/4ca3899a7370dcc7cfe132937f21a803 to your computer and use it in GitHub Desktop.
Save Arjun2002tiwari/4ca3899a7370dcc7cfe132937f21a803 to your computer and use it in GitHub Desktop.
class even implements Runnable{
synchronized public void run(){
for(int i=1;i<=20;i++){
if(i%2==0){
System.out.println(i);
}
}
}
}
class odd implements Runnable{
public void run(){
for(int i=0;i<=20;i++){
if(i%2!=0){
System.out.println(i);
}
}
}
}
public class Main4 {
public static void main(String[] args) {
Runnable obj = new even();
Runnable obj2 = new odd();
Thread t1 = new Thread(obj);
Thread t2 = new Thread(obj2);
t1.start();
t2.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment