Question
Can someone please convert this JAVA code to C code?(only C NOT C++ or C#) public class MultiThreading implements Runnable { @Override public void run()
Can someone please convert this JAVA code to C code?(only C NOT C++ or C#)
public class MultiThreading implements Runnable {
@Override public void run() { // numbers from 1 to 5000 try { for (int i = 1; i <= 5000; i++) { // odd number divisible by 9 if (i % 2 != 0 && i % 9 == 0) { System.out.println(Thread.currentThread().getName() + " : " + i); // sleep thread for 5 seconds Thread.sleep(5000); } }
} catch (InterruptedException e) { e.printStackTrace(); }
}
public static void main(String[] args) { // note: in order to create 3 threads, three objects must be created. single // object cannot be used // create object MultiThreading obj1 = new MultiThreading(); // create threads Thread ThreadOne = new Thread(obj1, "ThreadOne");
// create object MultiThreading obj2 = new MultiThreading(); // create threads Thread ThreadTwo = new Thread(obj2, "ThreadTwo");
// create object MultiThreading obj3 = new MultiThreading(); // create threads Thread ThreadThree = new Thread(obj3, "ThreadThree");
// start all threads ThreadOne.start(); ThreadTwo.start(); ThreadThree.start();
}
}
------------------------------------------------------------------
output:
In this program each thread will print each odd number divisible by 9 and sleep for 5 seconds.
The position of sleep(5000) can be changed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started