Programming Practice Java 1
The Closet Pair Problem
import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.*;
public class chuva
{
public static void main(String args[]) throws IOException
{
File f = new File(”C:\\x\\pair.txt”);
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
StringTokenizer st;
int limit;
int ctr =0;
int x[] = new int[10000];
int y[] = new int[10000];
String temp;
Double value;
Double answer = 10000.00;
DecimalFormat Currency = new DecimalFormat(”#0.0000″);
String finalna;
while (br.ready())
{
limit = Integer.parseInt(br.readLine());
if ( limit == 0 )
{
break;
}
else if ( limit > -1 && limit <= 10000 )
{
ctr = 0;
answer = 10000.00;
for ( int a=0; a
temp = br.readLine();
st = new StringTokenizer(temp);
x[ctr] = Integer.parseInt(st.nextToken());
y[ctr] = Integer.parseInt(st.nextToken());
ctr++;
}
for ( int a=0; a
for ( int b=0; b
if ( a!=b )
{
value = Math.sqrt(Math.pow((x[a]-x[b]),2)+Math.pow((y[a]-y[b]),2));
if ( value < answer )
{
answer = value;
}
}
}
}
if ( answer < 10000)
{
finalna = Currency.format(answer);
System.out.println(finalna);
}
else{
System.out.println("INFINITY");
}
}
else if ( limit > 10000){
for ( int a=0; a
br.readLine();
}
}
}
}
}







