Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

6 - 1 Show that in a PVT system, i = G i for a pure material.

Answered: 1 week ago

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago