Java Lab File Program
Java Lab File Program
1. Write a Java program to create a method that takes an integer as a parameter and
throws an exception if the number is a multiple of both 5 and 7,otherwise not
2. Write a Java program that reads a list of integers from the user and throws an exception
if any numbers are duplicates.
2)Write a Java program that demonstrates the basic concept of exception handling. Perform the
following steps:
• Create a method divideNumbers(int numerator, int denominator) that takes two integer
parameters: numerator and denominator.
• Inside the method, attempt to divide the numerator by the denominator.
• Use a try-catch block to handle any potential arithmetic exception that may occur (e.g.,
division by zero).
• Test your method by calling it with different values and observe the output
3)Extend the previous program to handle multiple types of exceptions. Perform the following steps:
• Test your method with different inputs to ensure all exceptions are handled correctly.
4)Write a Java program that demonstrates synchronization between multiple threads. Perform the
following steps:
• Use synchronization to ensure that only one thread can increment the counter at a time.