I have to cut double values to for digits, but i don't know how to do it with values from tables. i need to get from 0.254300 this 0.2543. This is my code, so how to cut extra zeros.
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();
}
}
}