Page 285 - Computer science 868 Class 12
P. 285
21 System.out.println("Number of students getting 34% and below : "+c2);
22 }
23 }
The output of the preceding program is as follows:
Number of students getting 80% and above : 4
Number of students getting 34% and below : 0
9.3 BASIC OPERATIONS ON ARRAY
The different operations that can be performed on an array are listed below.
• Searching
• Sorting
• Insertion
• Deletion
• Merging
Let us see in detail.
9.3.1 Searching
Searching is the way of finding an element in an array. We will deal with two different types of search – linear and binary.
Linear Search
It is the simplest technique of finding an element in an array. The searching begins from beginning and continues till
the end.
Program 4 Write a program to find an element in a double data type array.
1 class LinearSearch
2 {
3 public static void main(double n)
4 {
5 double arr[] = {3.5,7.8,4.5,9.8,55.4};
6 int i = 0,pos=-1;
7 for (i = 0; i < arr.length; i++)
8 {
9 if (arr[i] == n)
10 {
11 pos=i;
12 break;
13 }
283
Arrays 283

