我习惯了python和django,但我最近开始学习java.由于工作没有太多时间,我错过了很多课程,现在我有点困惑,因为我必须做一份工作.
编辑
该程序假设根据每个运动员在自行车和比赛中的时间来归属点.我有4个额外的男性和女性表,有点数和时间.
我必须比较然后找到每次的相应点(线性插值).
所以这是我的想法,读取文件,并使用arrayList
我遇到困难的一件事就是创建一个二维数组.
我有一个类似于这个文件:
12 M 23:56 62:50
36 F 59:30 20:60
Run Code Online (Sandbox Code Playgroud)
第一个数字是运动员,第二个是不同种族的性别和下一次(需要转换为秒数).
由于我不能将数组混合(int和char),我必须将性别转换为0和1.
那么到目前为止我做了什么:
public static void main(String[] args) throws FileNotFoundException {
Scanner fileTime = new Scanner (new FileReader ("time.txt"));
while (fileTime.hasNext()) {
String value = fileTime.next();
// Modify gender by o and 1, this way I'm able to convert string into integer
if (value.equals("F"))
value = "0";
else if (value.equals("M"))
value = "1";
// Verify which values has :
int index = valor.indexOf(":");
if (index != -1) {
String [] temp = value.split(":");
for (int i=0; i<temp.length; i++) {
// convert string to int
int num = Integer.parseInt(temp[i]);
// I wanted to multiply the first number by 60 to convert into seconds and add the second number to the first
num * 60; // but this way I multiplying everything
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道可能有更简单的方法来做到这一点,老实说,我有点困惑,欢迎任何灯光.
仅仅因为数组能够很好地存储一种语言的数据并不意味着它是以另一种语言存储数据的最佳方式.
您可以创建自定义类的单个数组(或集合),而不是尝试创建二维数组.
public class Athlete {
private int _id;
private boolean _isMale;
private int[] _times;
//...
}
Run Code Online (Sandbox Code Playgroud)
您打算如何使用数据可能会改变您构建类的方式.但这是您描述的数据线的简单直接表示.