$24
• Create a new project Lab05a. Write a program to generate 1000 random 4-digit numbers. Your program should compare the middle two digits of the number, and display all numbers whose middle two digits are the same. The program should also find and display the following:
◦ The highest number generated with same middle digits.
◦ The probability of generating a number with same middle digits.
◦ The average difference between the middle digits (if not the same middle digits)
Note: You can use the method, Math.random() which generates a random double value between 0 and 1 (0 inclusive, 1 exclusive) . You will have to do some calculations to convert the number to a 4-digit int. You are not alloed to use Math.round() method.
Sample run(taken with 100 4-digit ints):
b. Create a new project Lab05b. Write a program that takes an integer, n, and calculate the sum as follows:
You should validatethe user input as shown in the sample runs.
Sample runs:
c. Create a new project Lab05c. Your program prompts the user to enter a character, ch, and an int value, height, and then print out a triangle formed using chcharacters having a height of heightcharacters.
Sample run:
d. Create a new project Lab05d. Write a menu driven program, that asks the user to provide their selection. If any respense given other than the “Strings”, “Math”, and “Exit” (case-insensitive), the program should ignore that response and should continue to ask a valid selection.
If the selection is “strings”, it should ask two Strings from user and show the common characters in both Strings. It should be case-insensitive, meaning ‘A’ and ‘a’ should mean the same thing. There should be no duplicates, even if ‘a’ is found more than once, it should be displayed only once.
If the selection is “math”, it should ask the user to provide x, a real value between -1 and 1 (exclusive) , and a precision, a small positive real value less than 1. It should calculate the approximate value of 1 / (1 - x) by using the formula given below. Your program stops calculation whenever the increment is less than given precision value.
If the selection is “exit”, the program should say Goodbye and exit.
Sample interactions are shown below.
Sample runs:
4
5