This topic contains a solution. Click here to go to the answer

Author Question: What is the output of the following code?// Test.java: Define threads using the Thread classpublic ... (Read 28 times)

ashley

  • Hero Member
  • *****
  • Posts: 584
What is the output of the following code?

// Test.java: Define threads using the Thread class
public class Test {
/** Main method */
public static void main(String[] args) {
new Test();
}

public Test() {
// Create threads
PrintChar printA = new PrintChar('a', 4);
PrintChar printB = new PrintChar('b', 4);
// Start threads
printA.run();
printB.run();
}

class PrintChar implements Runnable {
private char charToPrint; // The character to print
private int times; // The times to repeat
/** Construct a thread with specified character and number of
times to print the character
*/
public PrintChar(char c, int t) {
charToPrint = c;
times = t;
}
/** Override the run() method to tell the system
what the thread will do
*/
public void run() {
for (int i = 0; i < times; i++)
System.out.print(charToPrint);
}
}
}

◦ character a and b are randomly printed
◦ ababababab
◦ bbbbbaaaaa
◦ aaaaabbbbb


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by ashley on May 6, 2020

duy1981999

  • Sr. Member
  • ****
  • Posts: 341
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 39% of students answer this correctly




ashley

  • Member
  • Posts: 584
Reply 2 on: May 6, 2020
Thanks for the timely response, appreciate it


Dinolord

  • Member
  • Posts: 313
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

Though newer “smart” infusion pumps are increasingly becoming more sophisticated, they cannot prevent all programming and administration errors. Health care professionals that use smart infusion pumps must still practice the rights of medication administration and have other professionals double-check all high-risk infusions.

Did you know?

There are immediate benefits of chiropractic adjustments that are visible via magnetic resonance imaging (MRI). It shows that spinal manipulation therapy is effective in decreasing pain and increasing the gaps between the vertebrae, reducing pressure that leads to pain.

Did you know?

Famous people who died from poisoning or drug overdose include, Adolf Hitler, Socrates, Juan Ponce de Leon, Marilyn Monroe, Judy Garland, and John Belushi.

Did you know?

Nearly all drugs pass into human breast milk. How often a drug is taken influences the amount of drug that will pass into the milk. Medications taken 30 to 60 minutes before breastfeeding are likely to be at peak blood levels when the baby is nursing.

Did you know?

Although not all of the following muscle groups are commonly used, intramuscular injections may be given into the abdominals, biceps, calves, deltoids, gluteals, laterals, pectorals, quadriceps, trapezoids, and triceps.

For a complete list of videos, visit our video library