0
クラスのプロジェクトで作業し、データを配列に読み込んだ後に問題が発生する。CSV入力のインポートと分割
エクセルのスプレッドシートでは、各ブロックの最初の数字だけに注意して列をまっすぐに読む必要があります。私は列を分割するときにスペースがない連続した文字列なので、各桁の数をカウントするのではなく、最初の桁をカウントするしか方法がわかりません。 例:(11、20、296)が分割され、 "1120296" になりつつ
final int[] benfordLaw = {0, 30, 18, 13, 10, 8, 7, 6, 5, 5};
int[] actualPrecent = new int[10];
int benfordScore = 0;
float[] countForNum = new float[10];
float totalCount = 0;
//This while loop will read through each line of the file
while (scan.hasNextLine()) {
// This statement reads in the next line of the file.
String line = scan.nextLine();
String[] values = line.split(",(?=(?:(?:[^\"]*+\"){2})*+[^\"]*+$)");
//12-15 is the column #'s
for (int i = 12; i < 15; ++i) {
for (int j = 0; j < values[i].length(); j++) {
char charA = values[i].charAt(j);
for (int k = 1; k <= 9; ++k){
char compare = (char)(k + '0');
if (charA == compare) {
++countForNum[k];
++totalCount;
}
}
}
}
}