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 27 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
Great answer, keep it coming :)


Missbam101

  • Member
  • Posts: 341
Reply 3 on: Yesterday
Excellent

 

Did you know?

Common abbreviations that cause medication errors include U (unit), mg (milligram), QD (every day), SC (subcutaneous), TIW (three times per week), D/C (discharge or discontinue), HS (at bedtime or "hours of sleep"), cc (cubic centimeters), and AU (each ear).

Did you know?

Throughout history, plants containing cardiac steroids have been used as heart drugs and as poisons (e.g., in arrows used in combat), emetics, and diuretics.

Did you know?

Studies show that systolic blood pressure can be significantly lowered by taking statins. In fact, the higher the patient's baseline blood pressure, the greater the effect of statins on his or her blood pressure.

Did you know?

People with high total cholesterol have about two times the risk for heart disease as people with ideal levels.

Did you know?

Always store hazardous household chemicals in their original containers out of reach of children. These include bleach, paint, strippers and products containing turpentine, garden chemicals, oven cleaners, fondue fuels, nail polish, and nail polish remover.

For a complete list of videos, visit our video library