我想把我的文本的double值放在2d数组上。我的文字有这样的把double值2d数组读取文本
我的文字从字符串
deneme deneme 4.5 5.5 6.6 7.5 9.9 9.9
dsdsa sddsf 9.9 8.7 7.5 8.8 4.4 6.5
ıextraxt双重价值双倍和字符串值。 我的节目输出为
4.5 5.5 6.6 7.5 9.9 9.9 9.9 8.7 7.5 8.8 4.4 6.5
我该怎么办我的输出六重奏。如果我能做到这一点,我将整理每行
FIRSTLINE:4.5 5.5 6.6 7.5 9.9 9.9
二线:9.9 8.7 7.5 8.8 4.4 6.5
public static void main(String[] args) throws IOException {
ArrayList<String> puan;
puan = okuDiziyeKoy("C:\\deneme\\HW.txt");
System.out.format("%d kayıt okundu.%n", puan.size());
for (int j = 0; j < puan.size(); j++) {
String point = puan.get(j);
String[] edit = point.split("[\\{\\}\\)]");
for (String s : edit) {
String a = s.replaceAll("[\\}\\-\\>\\>\\]\\[\\#\\*\\{]+", "");
String b = a.replaceAll("[\\.]+", ",");
Scanner scanner = new Scanner(b);
while (scanner.hasNext()) {
if (scanner.hasNextDouble()) {
Double doubleValue = scanner.nextDouble();
List<Double> numbers = new ArrayList<Double>();
numbers.add(doubleValue);
// System.out.println(Arrays.deepToString(numbers.toArray()));
final int col = 6;
final int rows = numbers.size() % col == 0 ? numbers.size()/col : numbers.size()/col + 1;
double[][] deneme = new double[rows][col];
for (int i = 0; i < rows; i++) {
for (int k = 0; k < col; k++) {
if (i == rows - 1 && k >= numbers.size() % col)
break;
deneme[i][k] = numbers.get(k + col * i);
System.out.print(deneme[i][k]+ " ");
}// for k end
System.out.println(); // go to next line
} // for i end
}// if scan end
else {
//if it is string comes value here
String stringValue = scanner.next();
}// if scan end
}// while end
}// for string s
}// for end
}// main end
我会在这里发表评论。完成输入后,您可以在'while'或'for'循环之外'恢复'和'打印'作业。你还需要在外面定义数字。 –