gpt4 book ai didi

java - 打印数组值之间的空格

转载 作者:行者123 更新时间:2023-12-01 15:09:41 25 4
gpt4 key购买 nike

我有这个代码,

else if (e.getSource() == saveButton) {
Scanner scan;
String es = " ";
try {
int status = chooser.showSaveDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
File newImageName = chooser.getSelectedFile();
PrintWriter outFile = new PrintWriter(new FileWriter(newImageName));
outFile.print(drawing.typefile);
outFile.print(drawing.iname);
outFile.print(drawing.width);
outFile.print(es);
outFile.print(drawing.height);
outFile.print(drawing.maxshade);
for(int r = 0; r < drawing.array.length; r++)
for(int c = 0; c < drawing.array[r].length; c++)
outFile.print(drawing.array[r][c]);


// outFile.print(drawing.paintComponent(newImageName));
outFile.flush();
outFile.close();
}
else if (status == JFileChooser.CANCEL_OPTION) {
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "File could not be written, try again.");
//ex.printStackTrace();
}

}

如何让它在值之间打印空格? 它打印

P2image1.pgm320 275255132132130125125128

我需要它来打印

P2image1.pgm320 275255132 132 130 125 125 128

因此每个数组值之间都有一个空格,我尝试了很多东西,但我完全困惑了。

谢谢。

最佳答案

只需在每个数字后明确打印一个空格即可。

您是否尝试过类似的操作:

for(int r = 0; r < drawing.array.length; r++) {
for(int c = 0; c < drawing.array[r].length; c++) {
outFile.print(drawing.array[r][c]);
outFile.print(" ");
}
}

关于java - 打印数组值之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12500432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com