Practice 70 Java Multithreading Programming Questions
Q1. Write a Java program to create a thread that prints "Hello, World!" five times.
Expected Output:
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Q2. Write a Java program to create two threads where one thread prints numbers from 1 to 5, and the other thread prints "Java" five times.
Expected Output:
1
2
3
4
5
Java
Java
Java
Java
Java
Q3. Write a Java program to create a thread that prints numbers from 1 to 10 with a 1-second delay between each number.
Expected Output:
1 (after 1 second)
2 (after 1 second)
3 (after 1 second)
...
10
Q4. Write a Java program to create two threads: one prints "Thread 1" and the other prints "Thread 2" in alternate turns.
Expected Output:
Thread 1
Thread 2
Thread 1
Thread 2
...
Q5. Write a Java program to demonstrate thread synchronization. Implement two threads that both try to increment a shared variable.
Expected Output:
Value of shared variable = 200 (assuming both threads increment it safely)
Q6. Write a Java program to create a thread that prints "Thread Active" five times with a 2-second delay.
Expected Output:
Thread Active
Thread Active
Thread Active
Thread Active
Thread Active
Q7. Write a Java program to implement a thread that calculates the sum of numbers from 1 to 100.
Expected Output:
Sum = 5050
Q8. Write a Java program to create a thread that prints a Fibonacci sequence up to the 10th term.
Expected Output:
0
1
1
2
3
5
8
13
21
34
Q9. Write a Java program to demonstrate thread communication using `wait()` and `notify()`.
Expected Output:
Thread 1 waiting
Thread 2 notified
Q10. Write a Java program to create two threads where one thread prints numbers from 1 to 5, and the other prints numbers from 6 to 10.
Expected Output:
1
2
3
4
5
6
7
8
9
10
Q11. Write a Java program to implement a thread that calculates the factorial of a number.
Input:
Number = 5
Expected Output:
Factorial of 5 = 120
Q12. Write a Java program to create a thread that prints a countdown from 10 to 1.
Expected Output:
10
9
8
7
6
5
4
3
2
1
Q13. Write a Java program to create a thread that prints the multiplication table of 2.
Expected Output:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
...
Q14. Write a Java program to create two threads where one prints "Java" and the other prints "Programming" alternately.
Expected Output:
Java
Programming
Java
Programming
...
Q15. Write a Java program to create a thread that calculates the sum of squares of numbers from 1 to 5.
Expected Output:
Sum of squares = 55
Q16. Write a Java program to demonstrate thread priorities by creating two threads, one with high priority and the other with low priority.
Expected Output:
High-priority thread output first
Low-priority thread output second
Q17. Write a Java program to create a thread that prints the first 5 multiples of 3.
Expected Output:
3
6
9
12
15
Q18. Write a Java program to implement a thread that checks whether a given number is prime.
Input:
Number = 7
Expected Output:
7 is prime
Q19. Write a Java program to create a thread that finds the largest number in an array.
Input:
Array = [1, 5, 3, 9, 2]
Expected Output:
Largest number = 9
Q20. Write a Java program to create a thread that simulates a task running for 5 seconds, then prints "Task Completed".
Expected Output:
Task Completed (after 5 seconds)
Q21. Write a Java program to create a thread that prints numbers from 1 to 20 with a 0.5-second delay.
Expected Output:
1 (after 0.5 second)
2 (after 0.5 second)
...
Q22. Write a Java program to create a thread that reverses a string.
Input:
String = "Java"
Expected Output:
avaJ
Q23. Write a Java program to create a thread that calculates the power of a number.
Input:
Base = 3, Exponent = 4
Expected Output:
3^4 = 81
Q24. Write a Java program to create a thread that finds the sum of even numbers between 1 and 50.
Expected Output:
Sum of even numbers = 650
Q25. Write a Java program to create two threads: one prints "Task A" and the other prints "Task B" simultaneously.
Expected Output:
Task A
Task B
(Task A and Task B print alternately)
Q26. Write a Java program to create a thread that prints all prime numbers between 1 and 50.
Expected Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Q27. Write a Java program to create a thread that prints the current system time every second.
Expected Output:
Time: [current time] (prints every second)
Q28. Write a Java program to create a thread that checks if a number is even or odd.
Input:
Number = 4
Expected Output:
4 is even
Q29. Write a Java program to implement a thread that checks if a given string is a palindrome.
Input:
String = "madam"
Expected Output:
madam is a palindrome
Q30. Write a Java program to create a thread that prints the first 10 numbers of the Fibonacci sequence.
Expected Output:
0 1 1 2 3 5 8 13 21 34
Q31. Write a Java program to create a thread that prints the factorial of a number recursively.
Input:
Number = 4
Expected Output:
Factorial of 4 = 24
Q32. Write a Java program to create a thread that prints the sum of digits of a given number.
Input:
Number = 123
Expected Output:
Sum of digits = 6
Q33. Write a Java program to create a thread that prints numbers divisible by 3 between 1 and 20.
Expected Output:
3 6 9 12 15 18
Q34. Write a Java program to create a thread that prints the first 5 perfect numbers.
Expected Output:
6 28 496 8128 33550336
Q35. Write a Java program to create a thread that calculates the sum of the first 50 natural numbers.
Expected Output:
Sum = 1275
Q36. Write a Java program to create a thread that calculates the sum of squares of numbers from 1 to 10.
Expected Output:
Sum of squares = 385
Q37. Write a Java program to create a thread that simulates a clock, printing the time every second.
Expected Output:
Time: [current time] (prints every second)
Q38. Write a Java program to implement a thread that simulates a countdown timer from a given number.
Input:
Number = 5
Expected Output:
5
4
3
2
1
Q39. Write a Java program to create a thread that calculates the sum of first 10 odd numbers.
Expected Output:
Sum = 100
Q40. Write a Java program to implement two threads that print numbers from 1 to 10, and the other prints "Java" 10 times.
Expected Output:
1
Java
2
Java
...
Q41. Write a Java program to create a thread that prints the sum of all multiples of 3 up to 100.
Expected Output:
Sum of multiples of 3 = 1683
Q42. Write a Java program to implement a thread that prints the square root of numbers from 1 to 10.
Expected Output:
Square roots = 1.0, 1.414, 1.732, ...
Q43. Write a Java program to create a thread that prints the sum of numbers from 1 to 50.
Expected Output:
Sum = 1275
Q44. Write a Java program to create a thread that checks whether a given number is a prime number or not.
Input:
Number = 11
Expected Output:
11 is prime
Q45. Write a Java program to create a thread that prints "Task Started", waits for 2 seconds, and then prints "Task Ended".
Expected Output:
Task Started
(Task waits for 2 seconds)
Task Ended
Q46. Write a Java program to implement a thread that finds the LCM of two numbers.
Input:
Number1 = 12, Number2 = 18
Expected Output:
LCM = 36
Q47. Write a Java program to create a thread that prints the reverse of an array of integers.
Input:
Array = [1, 2, 3, 4, 5]
Expected Output:
[5, 4, 3, 2, 1]
Q48. Write a Java program to create a thread that prints "Task Completed" after a 5-second delay.
Expected Output:
Task Completed (after 5 seconds)
Q49. Write a Java program to create a thread that prints the first 5 numbers in an arithmetic progression.
Input:
Start = 2, Difference = 3
Expected Output:
2, 5, 8, 11, 14
Q50. Write a Java program to create a thread that prints the multiplication table for any number.
Input:
Number = 7
Expected Output:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
...
Q51. Write a Java program to implement a thread that calculates the sum of squares of numbers from 1 to 10.
Expected Output:
Sum of squares = 385
Q52. Write a Java program to create a thread that prints the first 5 odd numbers.
Expected Output:
1
3
5
7
9
Q53. Write a Java program to create a thread that checks if a number is divisible by 5.
Input:
Number = 10
Expected Output:
10 is divisible by 5
Q54. Write a Java program to create a thread that prints the sum of even numbers from 1 to 100.
Expected Output:
Sum of even numbers = 2550
Q55. Write a Java program to create a thread that prints numbers from 1 to 20 in reverse order.
Expected Output:
20
19
...
1
Q56. Write a Java program to create a thread that calculates the sum of multiples of 4 up to 100.
Expected Output:
Sum of multiples of 4 = 1300
Q57. Write a Java program to create a thread that checks if a number is a perfect number.
Input:
Number = 28
Expected Output:
28 is a perfect number
Q58. Write a Java program to create a thread that finds the GCD of two numbers.
Input:
Numbers = 24, 36
Expected Output:
GCD = 12
Q59. Write a Java program to create a thread that prints the first 5 prime numbers.
Expected Output:
2 3 5 7 11
Q60. Write a Java program to create a thread that prints numbers divisible by 3 up to 50.
Expected Output:
3 6 9 12 15 18 ...
Q61. Write a Java program to create a thread that prints the first N Fibonacci numbers.
Input:
N = 5
Expected Output:
0 1 1 2 3
Q62. Write a Java program to create a thread that calculates the sum of cubes of numbers from 1 to 10.
Expected Output:
Sum of cubes = 3025
Q63. Write a Java program to create a thread that prints a countdown timer every second.
Expected Output:
10
9
...
1
Q64. Write a Java program to create a thread that prints the square of numbers from 1 to 5.
Expected Output:
1
4
9
16
25
Q65. Write a Java program to create a thread that prints the sum of multiples of 3 and 5 from 1 to 100.
Expected Output:
Sum = 2418
Q66. Write a Java program to implement a thread that finds the factorial of a number.
Input:
Number = 6
Expected Output:
Factorial of 6 = 720
Q67. Write a Java program to create a thread that prints all divisors of a given number.
Input:
Number = 28
Expected Output:
Divisors of 28 = 1 2 4 7 14 28
Q68. Write a Java program to create a thread that checks if a number is a prime number.
Input:
Number = 13
Expected Output:
13 is prime
Q69. Write a Java program to create a thread that prints the even numbers from 1 to 50.
Expected Output:
2 4 6 8 ... 50
Q70. Write a Java program to create a thread that prints the multiplication table of a number.
Input:
Number = 6
Expected Output:
6 x 1 = 6
6 x 2 = 12
...
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!