Computer Science, asked by alishanaaz9811, 8 months ago

Write a multithreaded program to generate the square roots of the first 30 natural numbers using runnable interface

Answers

Answered by basavaraj5392
0

Answer:

read prints 1 and the next thread prints 2 ,1st thread again prints 3 and so on. im a beginner so pls help me clearly. i thought thread share the same memory so they will share the i variable and print accordingly. but in output i get like thread1: 1, thread2 : 1, thread1: 2, thread2 : 2 nd so on. pls help. here is my code

class me extends Thread

{

public int name,i;

public void run()

{

for(i=1;i<=50;i++)

{

System.out.println("Thread" + name + " : " + i);

try

{

sleep(1000);

}

catch(Exception e)

{

System.out.println("some problem");

}

}

}

}

public class he

{

public static void main(String[] args)

{

me a=new me();

me b=new me();

a.name=1;

b.name=2;

a.start();

b.start();

}

}

Hope you satisfied with my answer.

Hope you satisfied with my answer.Please mark as brainly.

Similar questions