gpt4 book ai didi

java - double 值排序输出错误数据

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

我对大学类(class)有一些疑问。我也对作业的最后部分感到沮丧,我认为容易的部分很快就变成了最难的部分。系统要求我按距离对 .cvs 文件中的值进行排序(例如 17.0123874627346,0.123761947 等值)

这是我的代码:

public void sortDistance() {
System.out.println("before distance sort");
for (int k = 0; k < ntracks; k++) {
System.out.println(tracks[k].getDistance());
}
for (int i = 0; i < ntracks; i++) {
//find the index of the minimum position
int index = i;
//looping through array of distances
for (int j = i + 1; j < ntracks; j++) {
if (tracks[index].getDistance() < tracks[j].getDistance())
{
//position j is new mimum index
index = j;
}
}
//swap the two values around so smallest becomes track index
Track smallerTrack = tracks[index];
tracks[index] = tracks[i];
tracks[i] = smallerTrack;
}
System.out.println(" after distnace sort");
for (int k = 0; k < ntracks; k++) {
System.out.println(tracks[k].getDistance());
}
}

最佳答案

float s[]={1,3,2};Arrays.sort(s);

关于java - double 值排序输出错误数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26375025/

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