Due on 2024-03-28, 23:59 IST
Write a Java program that utilizes multithreading to calculate and print the squares of numbers from a specified begin to a specified end.
The main method is already created.
You need to design a SquareThread class that has two members,
Each thread should sequentially print the squares of numbers from begin to end (both inclusive).
The same code will be used to create another thread that prints the sqaure of numbers from end to begin in reverse order.
(if begin is greater than end, print the square of each number in reverse order first)
The main method will first call SquareThread with begin and end and then in reverse order.
The class you create should be able to handle such case and print as required in the correct order.
HINT: use the keyword `synchronized` in the run method.
Due on 2024-03-28, 23:59 IST
Complete the code segment to catch the exception in the following, if any.
On the occurrence of such an exception, your program should print
§ Please enter valid data
If there is no such exception, it will print the square of the number entered.
Due on 2024-03-28, 23:59 IST
The program given below stores characters in a byte array named byte_array, which means ‘A’ is stored as 65.
Your task is the following:
§ Given a user input `n`, print the output in the given format, if `n` = 1, print:
o byte_array[1] = ‘P’
§ If the value of n is negative or is out of bound, then use TRY_CATCH to print the following:
o Array index is out of range
Due on 2024-03-28, 23:59 IST
Define a class Point with members
§ private double x;
§ private double y;
and methods:
§ public Point(double x, double y){} // Constructor to create a new point?
§ public double distance(Point p2){} // Function to return the distance of this Point from another Point
Due on 2024-03-28, 23:59 IST
Complete the code below with a catch statement to print the following if the denominator (b) is zero
§ Cannot Divide by ZERO
No comments