Page 599 - Computer science 868 Class 12
P. 599
50 {
51 BinSearch obj = new BinSearch(s);
52 obj.fillarray();
53 obj.sort();
54 int p=obj.bin_search(0,s,v);
55 if(p==-1)
56 System.out.println(v+"not found in array ");
57 else
58 System.out.println(v+" found in location: " +(p+1));
59 }
60 }
Output of the preceding program is as follows:
Enter 5 elements
3
1
5
10
2
Sorted array
1 2 3 5 10
10 found in location: 5
Program 13 Binary to decimal using recursion
A class Binary is declared to converts a binary number to decimal. The details of the class is
as follows:
Data Members
long bin : to store a binary number.
long dec : to store a decimal number
int p : position
Member Functions
Binary() : to initialise the data member
void readBin() : to read a binary number
long convertDec(long a) : to convert binary number to its decimal equivalent
void show() : to display the result
Specify the class by giving details of constructors and functions and print the result.
1 import java.util.*;
2 class Binary
597
Internal Assessment 597

