• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can some one help me in this Prob plz

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, given is the code of my test Program here i have an Array of BigInteger of size 5 and there is and entry of String. I have to get 3 nearest Neighbour values of that String entered by the user.

Can some one suggest me how i can take those values...

Code Follows
//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; i++ ){
a = n[5].subtract(n[i]);

System.out.println("\n\nCalculation is = "+a.abs());}
}
}

//End of Code

Best Regards.
Salman
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Unfortunately I'm not really sure what you are trying to do. But i think your nearest neighbor problem is mostly a matter of what you define as nearest neighbors. Do you mean the neighbors regarding other BigIntegers already entered by some users?

If this is what you want to do then you could add the BigInteger objects to a List (e.g. an ArrayList) and use the static sort() method of the "Collections" helper class on this list to sort the list by the natural ordering of BigInteger. When the list is sorted you'll probably find what you mean by nearest neighbors.

And if you don't want to use the natural ordering of BigInteger you can still use this approach and define an additional Comparator for your objects. Then you can use the overloaded sort() method which takes a list and a comparator.

Hope this helps!

Marco
 
reply
    Bookmark Topic Watch Topic
  • New Topic