In: Computer Science
Q1. Write a Java program to do sequential search to find element 55 in array 10,20,35,45,55,65,75,85.
Q2.Write a Java program to find element 54 in array 45,41,65,53,76,90 using Binary Search. (Hint: Binary search is applied to sorted array elements)
Q4. Write a java program to create array list subject
- add English, Maths, Science to the list
- add Computers at index 2
- display first occurrence index of Maths
- traverse the list using for each loop.
Q5. Write a java program to create an ArrayList of user-defined class forobjects (Employee): for id,name,age. The employee data are as follows for creating class objects.
1101 Aamna 25
1111 Amjad 30
public class SeqSearch {
public static void main(String[] args) {
int arr[]= { 10,20,35,45,55,65,75,85};
int key=55;
int res=linerSearch(arr,key);
if(res==-1)
System.out.println(key+" does not exist in the array");
else
System.out.println(key+" found at index "+res);
}
private static int linerSearch(int[] arr, int key) {
// iterating through the array and checking if found returning the index
for(int i=0;i<arr.length;i++)
if(arr[i]==key)
return i;
return -1;
}
}
As per policy we can answer 1 question per post. Please post the remianing questions as separate post.Thanks