Lab Assignment 7
Lab Assignment 7
Programming Assignment-VII
(Single-Dimensional Arrays)
1. Write a java program to create an array of size N and store the random values in it and find the
sum and average.
2. Write a java program using an array that reads the integers between 1 and 100 and counts the
occurrences of each. Assume the input ends with 0. Here is a sample run of the program:
Note that if a number occurs more than one time, the plural word
“times” is used in the output.
3. Input 10 integers from the keyboard into an array. The number to be searched is entered through
the keyboard by the user. Write a java program to find if the number to be searched is present in
the array and if it is present, display the number of times it appears in the array.
4. Write a method that finds the smallest element in an array of double values using the following
header:
public static double min(double[] array)
Write a java program that prompts the user to enter ten numbers, invokes this method to return
the minimum value, and displays the minimum value. Here is a sample run of the program:
5. Write a java program to find the second largest value in an array of n elements.
6. Write a java program that implements the array reversal algorithm suggested in Note 1.
7. Write a java program to convert a decimal integer to its corresponding octal representation.
8. Design and develop a menu driven java program for the following array operations.
∑ 𝑥 𝑥 + 𝑥 +𝑥 + ⋯+ 𝑥
𝑚𝑒𝑎𝑛 = =
𝑛 𝑛
∑ (𝑥 − 𝑚𝑒𝑎𝑛)
𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 =
𝑛−1
Write a java program that prompts the user to enter ten numbers and displays the mean and
standard deviation, as shown in the following sample run:
10. Write a method that returns a new array by eliminating the duplicate values in the array using
the following method header:
Write a java program that reads in ten integers, invokes the method, and displays the result.
Here is the sample run of the program:
11. Write a sort method that uses the bubble-sort algorithm. The bubble sort algorithm makes
several passes through the array. On each pass, successive neighbouring pairs are compared. If a
pair is not in order, its values are swapped; otherwise, the values remain unchanged. The
technique is called a bubble sort or sinking sort because the smaller values gradually “bubble”
their way to the top and the larger values “sink” to the bottom. Write a java program that reads
in ten double numbers, invokes the method, and displays the sorted numbers.
12. The selection-sort method repeatedly finds the smallest number in the current array and swaps it
with the first. Write a java program that reads in ten integer values, invoke the method, and
displays the sorted elements.