Professional Documents
Culture Documents
Lab 7 Single Array Exercise PDF
Lab 7 Single Array Exercise PDF
1. Write a Java program to sum values of an array. Use the following array as a test case:
int [] my_array={1,2,3,4,5,6,7,8,9,10}
3. Write a Java program to test if an array contains a specific value. Use the following array as your test
case and the values to be searched are 2013 and 2015.
The test array: int[] my_array1 = {1789, 2035, 1899, 1456, 2013,
1458, 2458, 1254, 1472, 2365,1456, 2265, 1457, 2456};
4. Write a Java program to find the maximum and minimum value of an array. Use the following declaration
int[] my_array = {25, 14, 56, 15, 36, 56, 77, 18, 29, 49}; as your test case.
Sample Output:
Original Array: [25, 14, 56, 15, 36, 56, 77, 18, 29, 49]
Maximum value for the above array = 77
Minimum value for the above array = 14
5. Write a Java program to find the duplicate values of an array of string values. Assume the following
values as your string array:- {"bcd", "abd", "jude", "bcd", "oiu", "gzw", "oiu"}.
Sample Output:
Duplicate Element is : bcd
Duplicate Element is : oiu
6. Write a Java program to find the common elements between two arrays of integers. Use the following two
arrays as your test case.
a) int[] array1 = {1, 2, 5, 5, 8, 9, 7, 10} and
b) int[] array2 = {1, 0, 6, 15, 6, 4, 7, 0};
Sample Output:
Array1 : [1, 2, 5, 5, 8, 9, 7, 10]
Array2 : [1, 0, 6, 15, 6, 4, 7, 0]
Common element is : 1
Common element is : 7
7. Write a Java program to remove duplicate elements from an array. Assume the following array as a test
case. [new int [] {10, 22, 10, 20, 11, 22}]
Sample Output:
Original Array :
10 22 10 20 11 22
Array with unique values :
10 22 11 20
---------------------------