这个代码是循环的两倍!但不是双倍...只有一个循环>结束.. 请帮我.. 我想要一个双循环... 不要为hasNext()双重循环?
---------------------------编辑--------------
对不起。我犯了一个错误笨拙的英语。 "不要将双循环(While)设为HasNext()?"我在问什么。 对不起,我没有礼貌。 放"而"他" HasNext()"无法重复第一个循环。 我喜欢像乘法一样创造乘法。请帮帮我。
import java.io.IOException;
import java.net.MalformedURLException;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.shp.ShapefileException;
import org.geotools.data.shapefile.shp.ShapefileReader;
import org.geotools.data.shapefile.shp.ShapefileReader.Record;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
class Point {
double x;
double y;
Point(double x2, double y2) {
this.x = x2;
this.y = y2;
}
static double distance(Point p1, Point p2) {
double dist;
dist = Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
return dist;
}
}
public class KFunction {
private static double X;
private static double Y;
private static double X1;
private static double Y1;
public static void main(String[] args) {
ShapefileReader r = null;
ShapefileReader r2 = null;
try {
ShpFiles shpFile = new ShpFiles("Juvenile_Offenders_in_Cardiff.shp");
ShpFiles shpFile2 = new ShpFiles("Juvenile_Offenders_in_Cardiff.shp");
GeometryFactory geometryFactory = new GeometryFactory();
r = new ShapefileReader(shpFile, true, false, geometryFactory);
r2 = new ShapefileReader(shpFile2, true, false, geometryFactory);
Record record2 = r2.nextRecord();
Geometry shape2 = (Geometry) record2.shape();
com.vividsolutions.jts.geom.Point centroid2 = shape2.getCentroid();
int i = 0;
boolean A = r2.hasNext();
while (A) {
X = centroid2.getX();
Y = centroid2.getY();
while (r.hasNext()) {
System.out.println("No." + i);
Record record = r.nextRecord();
Geometry shape = (Geometry) record.shape();
com.vividsolutions.jts.geom.Point centroid = shape.getCentroid();
X1 = centroid.getX();
Y1 = centroid.getY();
Point p1 = new Point(X, Y);
Point p2 = new Point(X1, Y1);
double result = Point.distance(p1, p2);
System.out.println("X : " + X + " Y : " + Y + " X1 : " + X1 + " Y1 : " + Y1);
System.out.println("두 점 사이의 거리 : " + result);
System.out.println("---------------------------");
i++;
}
break;
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (ShapefileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:-1)
对我来说,它看起来像是外环,而(A)要么根本不做,要么永远不做,因为它看起来A永远不会改变它。