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 30 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
Excellent


jojobee318

  • Member
  • Posts: 298
Reply 3 on: Yesterday
:D TYSM

 

Did you know?

Anti-aging claims should not ever be believed. There is no supplement, medication, or any other substance that has been proven to slow or stop the aging process.

Did you know?

Your chance of developing a kidney stone is 1 in 10. In recent years, approximately 3.7 million people in the United States were diagnosed with a kidney disease.

Did you know?

There are 60,000 miles of blood vessels in every adult human.

Did you know?

Not getting enough sleep can greatly weaken the immune system. Lack of sleep makes you more likely to catch a cold, or more difficult to fight off an infection.

Did you know?

Most fungi that pathogenically affect humans live in soil. If a person is not healthy, has an open wound, or is immunocompromised, a fungal infection can be very aggressive.

For a complete list of videos, visit our video library