Hi guys,
Well i am trying to find out neastest two or three values which are closer to "str" value when compared with the rest of the values. All i want to know is what is the best possible way to get the closest match of query(str) from list of BigInteger. the Code is given Below
//Start Of Code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Vector;
class Testing1
{
public static void main(
String args[])
{
String a1, a2, a3, a4, a5, str="";
a1 = "04545b969af70c70e6379239ea701801a1dfcf1c";
a2 = "356a192b7913b04c54574d18c28d46e6395428ab";
a3 = "5ee5c0b94c86b17b8a51dac910235945a700aaeb";
a4 = "86b17b8a51dac91026379239ea701801a8736497";
a5 = "701801a1dfcf1c4545b969a5ee5c0b94c3546356";
BigInteger n[] = new BigInteger[6];
BigInteger a,b;
int mode;
n[0] = new BigInteger(a1, 16);
n[1] = new BigInteger(a2, 16);
n[2] = new BigInteger(a3, 16);
n[3] = new BigInteger(a4, 16);
n[4] = new BigInteger(a5, 16);
try
{
BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in));
System.out.print("\n\n\n\t\tEnter Qeuery string <> ");
str = userInput.readLine();
str = MySHA1.SHA1(str);
}
catch(Exception e)
{}
n[5] = new BigInteger(str, 16);
System.out.println("Hash Value of Query String is "+str+"\n\n\nBig Integer Value of String is "+n[5]);
for(int i=0; i<n.length-1; i++ ){
a = n[5].subtract(n[i]);
a = a.abs();
System.out.println("\n\nCalculation is = "+a);
//Here I want to comparison b/w a and n[i] want the 2 closest values from n[i]. How can i get those?
}
}
}
//End of Code
Best Regards.
Salman