Page 270 - computer science (868) class 11
P. 270
Here, len will contain the length of the array. Let us consider the following example.
Program 7 Write a program to calculate the length of an array.
1 class length_array
2 {
3 public static void main()
4 {
5 int i;
6 String player_name[ ]={"Sourav", "Sanchin", "Rahul", "Suresh", "Bumra"};
7 int len=player_name.length;
8 System.out.println("Total Number of players: " + len);
9 System.out.print ("Name of players are: ");
10 for(i=0; i<len; i++)
11 {
12 System.out.print (player_name[i]+" , ");
13 }
14 }
15 }
The output of the preceding program is as follows:
Total Number of players: 5
Name of players are: Sourav, Sanchin, Rahul, Suresh, Bumra
10.4 DIFFERENT OPERATIONS ON A SINGLE-DIMENSIONAL ARRAY
Different types of operations which can be performed on an array are searching, sorting, insertion, deletion and
merging. Let us learn about them in detail.
10.4.1 Searching
Searching is used to determine whether an element is present in the array or not. In this class, we shall learn about
linear search and binary search.
Linear Search
The other name for linear search is sequential search. In this technique, the element to be found is searched from the
1st position of the array till the last position. If found, the search will stop.
Let us take the following example in which ar is the name of the array of length 5.
Position or index 0 1 2 3 4
Ar 2 4 5 7 9
Suppose, the number to be searched: 5
268268 Touchpad Computer Science-XI

