Professional Documents
Culture Documents
Lab 6 Dsa
Lab 6 Dsa
Lab 6 Dsa
Object:
To find an element in linear array using Linear Search and Binary Search
Lab Tasks:
1. Declare an array of size 10 to store account balances. Initialize with values 0 to
1000000. Check all array if any value is less than 10000. Show message:
Account No .. Low Balance
Account No .. Low Balance
Code:
package Lab5;
public class Task1 {
public static void main(String[] args) {
int[] balances = new int[10];
balances[0] = 200;
balances[1] = 1000;
balances[2] = 3000;
balances[3] = 240000;
balances[4] = 15000;
balances[5] = 10;
balances[6] = 123456;
balances[7] =0;
balances[8] = 400000;
balances[9] = 345678;
OUTPUT:
2. Write a program to search in array using Array built-in class.
Code:
package Lab6;
import java.util.*;
OUTPUT:
Home Task:
1. Write a function called occurrences that, given an array of numbers A, prints all
the distinct values in A each followed by its number of occurrences. For example,
if A = (28, 1, 0, 1, 0, 3, 4, 0, 0, 3), the function should output the following five lines
(here separated by a semicolon) “28 1; 1 2; 0 4; 3 2; 4 1”.
Code:
package Lab6;
import java.util.*;
}
public static void getOccurrences(int[] numbers){
Arrays.sort (numbers);
int count = 0;
int start = 0;
int move = 0;
OUTPUT: