java - 获取方法被调用的问题
问题描述
我似乎无法得到坐标以上和百分比以上来输出任何内容。我有一个 List<> coordinatesAbove 方法,它采用高度并将纬度和经度放入列表中。然后,我需要计算出我在新列表中拥有的所有坐标与旧列表相比的百分比。我下面有这个。每当我运行它时,我似乎无法获得要输入的百分比。
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.List;
public class Map {
static double[][] array;
double longitude, latitude;
double alti;
public static void main(String[] args) throws FileNotFoundException {
Map m = new Map();
m.readDataArray("earth.xyz");
System.out.println(Arrays.deepToString(array));
m.coordinatesAbove(-2000);
m.percentageAbove(-2000);
System.out.println(percentage);
}
public void readDataArray(String filename) throws FileNotFoundException {
Scanner input = new Scanner(new File(filename));
int countLines = 0;
while (input.hasNextLine()) {
countLines++;
input.nextLine();
}
array = new double[2336041][3];
input.close();
input = new Scanner(new File(filename));
String curLine;
double longitude, latitude;
double alti;
countLines = 0;
while (input.hasNextLine()) {
curLine = input.nextLine();
String[] curData = curLine.split("\t");
longitude = Double.parseDouble(curData[0]);
latitude = Double.parseDouble(curData[1]);
alti = Double.parseDouble(curData[2]);
array[countLines][0] = longitude;
array[countLines][1] = latitude;
array[countLines][2] = alti;
countLines++;
}
}
public List<Double> coordinatesAbove(double altitude){
List<Double> coordinatesAbove = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
coordinatesAbove.add(array[i][2]);
}
coordinatesAbove.removeIf(a -> a < altitude);
return coordinatesAbove;
}
public double percentageAbove(double altitude) {
double percentage = 0;
for (int i = 0; i < array.length; i++) {
if (coordinatesAbove(-2000).contains(array[i][2]))
percentage = percentage + 100 / array.length;
}
return percentage;
}
}
解决方案
您的方法返回结果,但您没有将其分配到任何地方。
m.percentageAbove(-2000);
应该
double percentage = m.percentageAbove(-2000);
推荐阅读
- c++ - 您可以将“cin”与字符串一起使用吗?
- groovy - 我们可以在 Spock 功能规范中的同一个测试用例中处理异常和响应吗
- css - 无法调整卡片内的图像
- wordpress - 如何解决 Wordpress 中的 500 错误问题?
- elasticsearch - Elasticsearch 为每个文档添加时间戳 - 创建于并更新于
- powershell - 在 PowerShell 中检查文件中的最后一行是否为空
- html - 目的是什么
在角度 8 中,它是如何使用的? - java - 在改造后api android中发送多个数据类型参数
- mysql - 我的 Apache 和 Mysql 没有在 xampp 中启动
- authentication - 使用私钥的 ssh 身份验证问题