java(Syntax error, insert “;” to complete LocalVariableDeclarationStatement)
1、缺少“;”标点在句尾
2、句中有中文空格
3、“;”的大小写问题
4、String[][] getFileInput(String Path) throws Exception {
private static double[][] getFileInput(String pathName) throws Exception {
txt转化为二维数组
(1)private static double[][] getFileInput(String pathName) throws Exception {
FileInputStream inputStream = null;
Scanner sc = null;
List<double[]> list = new ArrayList<>();
inputStream = new FileInputStream(pathName);
sc = new Scanner(inputStream, “utf-8”);
while (sc.hasNextLine()) {
String line = sc.nextLine();
int s = 0;
String[] arr = line.split(",");
double[] dArr = new double[arr.length];
for (String ss : arr) {
if (ss != null) {
dArr[s++] = Double.parseDouble(ss);
}
}
list.add(dArr);
}
int max = 0;
for (int i = 0; i < list.size(); i++) {
if (max < list.get(i).length)
max = list.get(i).length;
}
double[][] array = new double[list.size()][max];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < list.get(i).length; j++) {
array[i][j] = list.get(i)[j];
}
}
inputStream.close();
sc.close();
return array;
}
(2)private static double[][] getFileInput(String pathName) throws Exception {
FileInputStream inputStream = null;
Scanner sc = null;
List<double[]> list = new ArrayList<>();
inputStream = new FileInputStream(pathName);
sc = new Scanner(inputStream, “utf-8”);
while (sc.hasNextLine()) {
String line = sc.nextLine();
int s = 0;
String[] arr = line.split(",");
double[] dArr = new double[arr.length];
for (String ss : arr) {
if (ss != null) {
dArr[s++] = Double.parseDouble(ss);
}
}
list.add(dArr);
}
int max = 0;
for (int i = 0; i < list.size(); i++) {
if (max < list.get(i).length)
max = list.get(i).length;
}
double[][] array = new double[list.size()][max];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < list.get(i).length; j++) {
array[i][j] = list.get(i)[j];
}
}
inputStream.close();
sc.close();
return array;
}
作者:fengzhimohan
来源:CSDN
原文:https://blog.csdn.net/fengzhimohan/article/details/84644523