我喜歡用Joptionpane居中數據的數據,我看着string.format和其他,但沒有任何幫助,我想要的東西像矩陣中的所有信息,它下降彼此和一個「|」到separete每一列Java數組2d數組中心字符串數據類型
在數據犯規alignt的信息的信息
score [0][0]="Empresa "
score [0][1]="Guanacaste";
score [0][2]="Alajuela";
score [0][3]="Heredia";
score [0][4]="San Jose";
score [0][5]="Cartago";
score [0][6]="Limon";
score [0][7]="Puntarenas";
score [0][8]="Total";
score [0][9]="Porcentaje";
score [1][0]="SOIN"+" ";
score [2][0]="AVANTICA"+" ";
score [3][0]="INNOVASOFT ";
score [4][0]="CRUX"+" "+" ";
score [5][0]="NCQ"+" "+" ";
這是陣列:String [][] score= new String[6][10];
public static void Output() {
int l = 0;
String data = "";
if (score[0][0] != (null)) {
while (l < score.length) {
for (int i = 0; i < 10; i++) {
if (score[l][i] == null) {
score[l][i] = "0";
}
data += " | " + score[l][i];
if (i == 9) {
data += " |";
}
}
l++;
data += "\n";
}
JOptionPane.showMessageDialog(null, data);
} else {
JOptionPane.showMessageDialog(null, "No se han ingresado datos", "Datos ingresados", JOptionPane.INFORMATION_MESSAGE);
}
}
可能重複[在JOptionPane中對齊字符串](https://stackoverflow.com/questions/14797845/aligning-a-string-in-joptionpane) – nullpointer
[鏈接](https://stackoverflow.com/ questions/14797845/aligning-a-string-in-joptionpane)does not work whit我的問題 –
你是什麼意思的「不工作」? –