我宣布了一个全局向量,我尝试全局访问它,但它会引发错误。
它说无法找到符号XArray或YArray。
我使用的代码(我已经删除了一些我认为没有必要的代码):
public class Main {
public static void main(String[] args) {
String csvFile = "/Users/hherzberg/Desktop/testData.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
ArrayList<Point3D> myPoints = new ArrayList<Point3D>();
ArrayList<Double> XArray = new ArrayList<Double>();
ArrayList<Double> YArray = new ArrayList<Double>();
try {
int xcount=0;
int ycount=0;
double multiplied=0;
br = new BufferedReader(new FileReader(csvFile));
br.readLine();
while ((line = br.readLine()) != null) {
// use comma as separator
String[] number = line.split(cvsSplitBy);
double x = Double.parseDouble(number[0]);
double y = Double.parseDouble(number[1]);
XArray.add(x);
YArray.add(y);
Point3D p = new Point3D(x, y);
myPoints.add(p);
xcount+=1;
ycount+=1;
System.out.println(p);
}
for (int i=0; i<myPoints.size();i++)
{
multiplied+=Double.parseDouble(XArray(i))*Double.parseDouble(YArray(i+1));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
非常感谢对此的一些帮助。
答案 0 :(得分:0)
在第一行使用以下导入,它应该可以正常工作
Accept-Encoding: gzip