Can someone please find out whats wrong with the code. it works fine on my laptop but shows WRONG ANSWER here. It gives same sample output for the given sample input.
Thanks in advance.
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
int n = 0;
int numTestCases = scanner.nextInt();
while (n < numTestCases) {
double innerRad = scanner.nextDouble();
double outerRad = scanner.nextDouble();
double carDia = 0;
int numObstacles = scanner.nextInt();
int i = 0;
int j = 0;
double[][] obstacles = new double[numObstacles][2];
while (i < numObstacles) {
obstacles[i][0] = scanner.nextDouble();
obstacles[i][1] = scanner.nextDouble();
i++;
}
if (numObstacles == 0) {
carDia = (outerRad - innerRad);
} else {
while (j < numObstacles) {
double dist = Math
.sqrt((obstacles[j][0] * obstacles[j][0])
+ (obstacles[j][1] * obstacles[j][1]));
double diff1 = dist - (innerRad);
double diff2 = (outerRad) - dist;
if (diff1 > 0 && diff2 > 0) {
if (diff1 > diff2) {
carDia = diff1;
} else {
carDia = diff2;
}
} else {
carDia = (outerRad - innerRad);
}
j++;
}
}
DecimalFormat df = new DecimalFormat(“0.000”);
String finalVal = df.format(carDia);
System.out.println(finalVal);
}
scanner.close();
n++;
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}