This program reads float values, but displays it up to 8 decimal digits by rounding off the input values in the text file. Can someone tell me how to read the value and print exactly the same value? A simple Java program (Hint - can be read as a string) I'm a beginner in Java, so don't know much of the stuff. I don't know how to implement it.
import java.util.Scanner;
import java.io.File;
public class read {
public static double[][] readData(String filename) throws Exception {
double[][] matrix = {{1}, {2}};
File inFile = new File(filename);
Scanner in = new Scanner(inFile);
int intLength = 0;
String[] length = in.nextLine().trim().split("\\s+");
for (int i = 0; i < length.length; i++) {
intLength++;
}
in.close();
matrix = new double[intLength][intLength];
in = new Scanner(inFile);
int lineCount = 0;
while (in.hasNextLine()) {
String[] currentLine = in.nextLine().trim().split("\\s+");
for (int i = 0; i < currentLine.length; i++) {
matrix[lineCount][i] = Float.parseFloat(currentLine[i]);
}
lineCount++;
}
return matrix;
}
public static boolean isMagicSquare(int[][] square) {
return false;
}
public static void main(String args[])
{
double[][] mat;
try {
mat = readData("readsample.txt");
int ii = 347;
int jj = 697;
for(int i = 0; i < ii; i++) {
for(int j = 0; j < jj; j++) {
System.out.print(mat[0][0] + " ");
}
System.out.println(" ");
}
System.out.print(mat[i][j] + " ");
double m1 = mat[0][0], m2 = mat[0][0];
for(int i = 0; i < ii; i++) {
for(int j = 0; j < jj; j++) {
if(mat[i][j] < m1) {
m1 = mat[i][j];
}
//if(m2 > mat[i][j])
// m2 = mat[i][j];
}
}
System.out.print(m1 + " ");
}
catch(Exception e) { }
}
}