Question: Solution must have java language and add comments. Suppose you are given the following code: class FooBar { public void foo ( ) { for
Solution must have java language and add comments. Suppose you are given the following code:
class FooBar
public void foo
for int i ; i n; i
printfoo;
public void bar
for int i ; i n; i
printbar;
The same instance of FooBar will be passed to two different threads:
thread A will call foo while
thread B will call bar
Modify the given program to output "foobar" n times.
Example :
Input: n
Output: "foobar"
Explanation: There are two threads being fired asynchronously. One of them calls foo while the other calls bar
"foobar" is being output time.
Example :
Input: n
Output: "foobarfoobar"
Explanation: "foobar" is being output times.
Constraints:
n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
