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 31 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 :)


parker125

  • Member
  • Posts: 332
Reply 3 on: Yesterday
Thanks for the timely response, appreciate it

 

Did you know?

The first documented use of surgical anesthesia in the United States was in Connecticut in 1844.

Did you know?

ACTH levels are normally highest in the early morning (between 6 and 8 A.M.) and lowest in the evening (between 6 and 11 P.M.). Therefore, a doctor who suspects abnormal levels looks for low ACTH in the morning and high ACTH in the evening.

Did you know?

Patients who cannot swallow may receive nutrition via a parenteral route—usually, a catheter is inserted through the chest into a large vein going into the heart.

Did you know?

Each year in the United States, there are approximately six million pregnancies. This means that at any one time, about 4% of women in the United States are pregnant.

Did you know?

People about to have surgery must tell their health care providers about all supplements they take.

For a complete list of videos, visit our video library