Counting threads Write a java program that asks the user for two different positive integers. Use either a while loop or a do-while loop to force the user to re-enter the numbers if they try to enter a negative or zero. Then create two threads. Each thread will count up to one of the numbers given by the user, printing out as they go. Make sure the Threads have a private String instance variable so that they can be distuinguished. In the following example I gave one thread the letter A and the other the letter B. Instantiate, start, and join each of the threads so that they are running concurrently. An example interaction might look like the following: Give me a number: 7 Give me a number: 5 A:0 A:1 A:2 B:0 B:1 A:3 A:4 B:2 A:5 B:3 A:6 B:4 A:7 B:5
Counting threads
Write a java
Then create two threads. Each thread will count up to one of the numbers given by the user, printing out as they go. Make sure the Threads have a private String instance variable so that they can be distuinguished. In the following example I gave one thread the letter A and the other the letter B.
Instantiate, start, and join each of the threads so that they are running concurrently.
An example interaction might look like the following:
Give me a number: 7
Give me a number: 5
A:0
A:1
A:2
B:0
B:1
A:3
A:4
B:2
A:5
B:3
A:6
B:4
A:7
B:5
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)