```
<%!
public String haversine(String lat1,String lon1,String lat2,String lon2)
{
int r = 6371;
String val=null;
double dlat=((Double.parseDouble(lat2))-(Double.parseDouble(lat1)));
double dlon=((Double.parseDouble(lon2))-(Double.parseDouble(lon1)));
double a = (Math.sin(dlat/2)*Math.sin(dlat/2))+(Math.cos(Double.parseDouble(lat1))*(Math.PI/180))*(Math.cos(Double.parseDouble(lat2))*(Math.PI/180))*(Math.sin(dlon/2)*Math.sin(dlon/2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double d = r * c;
if(d>1)
val= ((d)) +"km";
else if(d < =1)
val = ((d*1000)) +"m";
return val;
}
%>
```

this is how i call the above function and print it

```
<%
String hav = haversine(lat.substring(0, lat.indexOf(",")), lat.substring(lat.indexOf(",") + 1, lat.length()), abc.substring(0, abc.indexOf(",")), abc.substring(abc.indexOf(",") + 1, abc.length()));
%>
<td><font color ="white"><% out.println(hav);%></font>
```

i get a very wrong output for the above prog,,pls help,,