Created
December 14, 2021 19:10
-
-
Save Arjun2002tiwari/4ca3899a7370dcc7cfe132937f21a803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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