0
我必須將雙精度值切分爲數字,但我不知道如何使用表中的值來完成此操作。我需要從0.254300這個0.2543中獲得。 這是我的代碼,所以如何削減額外的零。在表格中將雙精度值切分爲4位數
public class Diagonal{
public static void main(String[] args){
double [][] tab = new double [5][5];
for (int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++){
tab[i][j] = (int) (Math.random() * 9000)/10000.0;
}
}
for(int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++)
if(i==j || i+j==4)
System.out.printf("%4f", tab[i][j]);
else
System.out.printf("%4c",' ');
System.out.println();
}
}
}
這就是我需要的。只是一點點開關,謝謝 – Johny