I want to create two threads.One thread will have to print odd numbers and the other thread will have to print even numbers between 1-20 numbers. This is the code I have attempted so far but it doesn't give the expected output.
public class JavaApplication40 extends Thread {
@Override
public void run(){
while (true){
for (int i=0;i<=20;i++){
if(i%2!=0){
System.out.println("odd " +i);
}
}
}
}
public static void main(String[] args) {
Thread t =new JavaApplication40();
for (int x=0;x<=20;x++){
if(x%2==0){
System.out.println("even " + x);
}
}
}
}
This code only outputs even numbers.I want odd numbers too.Someone please tell me how I can modify the above code to get the expected output.