-5
public void fitModel(String opFileName) {
    double alpha = 0.477;
    double[][] data = new double[time.length][order];
    for (int row = 0; row < time.length; row++) {
        for (int col = 0; col < order; col++) {
            data[row][col] = Math.tanh(alpha * (col + 1) * time[row]);
        }
    }
    computeCoeff(data);
    doPrediction(data, opFileName, true);

    }

    System.out.println();
    System.out.println("Model Parameters :");
    for (int i = 0; i < coeff.length; i++) {
        System.out.println(coeff[i]);
    }

    System.out.println();
    System.out.println("% deviation : " + deviation
            / (prediction.length - zeroRecCnt));
}

}

The command prompt displays three coloumns input,output, prediction . I need to read these three coloumns , and write the data to a text file . CAn you please help me out with this .

Tanya Rao
  • 15
  • 1
  • 5
  • There are thousands of tutorials that will teach you how to do this, I suggest you use one. – Supericy May 23 '13 at 07:53
  • How is the code you are showing related to the question you are asking? – fGo May 23 '13 at 07:55
  • I added part of the code since the program contains more than 100 lines of code and the program uses methods defined in another class ,which has another 200 lines of code . My question is specific to , how one can read data from the command prompt and write it to a text file. Thanks. – Tanya Rao May 23 '13 at 08:03
  • I think you could better modify that code segment because is not helping to clarify what you are asking. Anyways, if you want to read some data from the input and the write it take a look at the first answer – fGo May 23 '13 at 08:06
  • you could also read http://stackoverflow.com/questions/7637290/get-command-prompt-output-to-string-in-java?rq=1 – fGo May 23 '13 at 08:07
  • Please check the code once again . I need to read the coeff[i] , and %deviation data and write in to a text file – Tanya Rao May 23 '13 at 09:18
  • just adapt the answer to your needs, something like `coeff[i] = scanner.nextInt();` – fGo May 23 '13 at 12:08

1 Answers1

0

Scanner could be a good option:

Scanner scanner = new Scanner(new InputStreamReader(System.in));
System.out.println("Reading input from console using Scanner in Java ");
System.out.println("Please enter your input: ");
String input = scanner.nextLine();
System.out.println("User Input from console: " + input);
System.out.println("Reading int from console in Java: ");
int number = scanner.nextInt();
System.out.println("Integer input: " + number);
fGo
  • 1,146
  • 5
  • 11
  • Then you can write it as: `File file = new File("/users/mkyong/filename.txt"); FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(input); bw.close();` – fGo May 23 '13 at 07:54