Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不要像HasNext()那样做双循环(While)?_Java_While Loop_Distance - Fatal编程技术网

Java 不要像HasNext()那样做双循环(While)?

Java 不要像HasNext()那样做双循环(While)?,java,while-loop,distance,Java,While Loop,Distance,这个代码是双while循环!但不是双重的。。。只有一个循环>结束。。 请帮帮我。。 我想要一个双圈的。。 是否对hasNext()进行双循环 ---------------------------编辑-------------- 对不起。我做了​​一个笨拙的英语错误。 “不要像HasNext()那样做双循环(While)”,我想问的是。 对不起,我没有礼貌。 把“While”他“HasNext()”放在不能重复第一个循环的地方。 我想创造像乘法一样的东西。请帮帮我 import java.io.

这个代码是双while循环!但不是双重的。。。只有一个循环>结束。。 请帮帮我。。 我想要一个双圈的。。 是否对hasNext()进行双循环

---------------------------编辑--------------

对不起。我做了​​一个笨拙的英语错误。 “不要像HasNext()那样做双循环(While)”,我想问的是。 对不起,我没有礼貌。 把“While”他“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();
        }
    }
}

在我看来,(A)的外环要么根本不做,要么永远不做,因为它里面的A永远不会改变。

请不要在标题中哭。我现在哭了,请澄清你的问题,“我想要一个双环”太广泛了,我们帮不了你,你不能既不想要又想要……好吧,你可以,但这毫无意义。你是否想要一个双人
while
,如果不想要,你认为应该用什么来代替那个有问题的双人