gpt4 book ai didi

java - 如果满足该语句,则中断 while 语句及其后面的代码

转载 作者:行者123 更新时间:2023-12-01 22:18:50 25 4
gpt4 key购买 nike

如果距离小于 15,我会尝试返回 routeList,并且如果是这种情况,请勿在 while 语句之后运行代码。目前,routelist 正在 if 语句中被覆盖。我怎样才能达到这个目标?

感谢任何帮助。

    public ArrayList<Integer> detectRoute(double latD, double longD) {

ArrayList<Integer> routeList = new ArrayList<Integer>();
.
.
.
PreparedStatement preparedLatLongName = con
.prepareStatement("SELECT lat, longi, name from stops");
ResultSet rsLLN = preparedLatLongName.executeQuery();

// ArrayList<Double> distanceHistory = new ArrayList<Double>();
List<StopItem> distanceHistory = new ArrayList<>();

while (rsLLN.next()) {
double latStop = rsLLN.getDouble("lat");
double lonStop = rsLLN.getDouble("longi");
String nameStop = rsLLN.getString("name");
double distStop = haversineDistance(latD, longD, latStop,
lonStop);
StopItem newItem = new StopItem(nameStop, distStop );
distanceHistory.add(newItem);


// TODO add the speed here.
if (distStop <= 15) {
routeList = getByStop(con, calendar, WDay, rsLLN);
break;
}

}
//Find the shortest distance and its related longi and lati
Collections.sort(distanceHistory);
double shortestDistance = distanceHistory.get(0).getStopDist();
String nameShortestDistance = distanceHistory.get(0).getNameStop();
.
.
.
.
return routeList;
}

最佳答案

您甚至不必打破循环。只需将 break 替换为 returnrouteList 即可。

关于java - 如果满足该语句,则中断 while 语句及其后面的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com