The document discusses three ways to manipulate array data: searching, accumulating, and reversing elements. It provides code examples to search an array for a value and return its index, add corresponding elements of two arrays into a third array, and read numbers into an array and print them in reverse order.
3. Searching a value
Eg.- A method to search an array of integer
The Search method return the location of the first
array element equal to the search value
int Search (int[ ] num, int search value){
int location;
for (i=0; i =num.length; i++)
if(num[i] = = search Value)
location = i;
return location;
}
4. Assume the num values as below:
int[] num = {10,20,30,40,50,60,70,80,90,100}
If searchValue is 60, the method will
return 5 to Search method.
4
40
10
20
30
50
60
70
80
90
100
num[0]
num[1]
num[2]
num[3]
num[4]
num[5]
num[6]
num[7]
num[8]
num[9]
Location, i
5. Calculation in array
Eg:- add a number from Array1 and Array2, and store
the total in Array3
Assume Array1, Array2 and Array3
declarations as below:
int[ ] Array1 = {10,20,30,40,50,60,70,80,90,100};
int[ ] Array2 = {11,22,33,44,55,66,77,88,99,110};
int[ ] Array3 = new int[10];
9. Reverse element
Eg- Read 10 integer numbers, and print the
numbers in reverse order
public static void ReverseOrder()
{
int item[] = new int[10];
int i;
//Read integers number and store in item[i]
System.out.println("Enter ten integers number:");
for(i = 0; i < 10; i++)
item[i] = input.nextInt();
//Print the output in reverse order are:");
System.out.println("The numbers in reverse order are:");
for(i = 9; i >= 0; i--)
System.out.println(item[i]);
}
10. Output Enter ten integers number:
56
65
67
43
64
76
39
77
47
84
The numbers in reverse order are:
84
47
77
39
76
64
43
67
65
56