hi everyone!

I would like to know how you can put a matrix that came from c + + code in the Java console in an matrix in java. In fact, I send parameter to my c + + code from the java code, and the receipt of income is at the java console in the form of a text. so, I want to extract the matrix from the text .I need later in the code, I honestly do not know how.

below, this is my java code

OutputStream out = null;
     OutputStream err = null;
     PipedInputStream pipedInput = new PipedInputStream();
     PipedOutputStream pipedOutput = new PipedOutputStream(pipedInput);
     Program prog = new Program("C:\\Users\\abdelhalim\\Desktop\\ExempleMMKP33.exe", System.out, System.err, pipedInput);
        // TODO: Write pipedOutput from your favorite thread to send input to the program and finally close the stream.
        // I will use a PrintWriter because we are working here with text and not binary data.
        PrintWriter pw = new PrintWriter(pipedOutput);
        // println outputs platform specific newline but pw.print("5\n" ) would also convert "\n" to platform specific newline.


       res1= new int[n][m];
        pw.println(m);
        pw.println(n);
        pw.println(m);
        pw.println(n);

        for(int k=0; k<R.size();k++)
        { 
        pw.println(R.get(k));
        }

        for(int k=0; k<C.size();k++)
        {

        pw.println(C.get(k));
        }
        for(int k=0; k<B.size();k++)
        {

        pw.println(B.get(k));
        }
        for(int k=0; k<Dr.size();k++)
        {

        pw.println(Dr.get(k));
        }
        for(int k=0; k<Dc.size();k++)
        {

        pw.println(Dc.get(k));
        }
        for(int k=0; k<Db.size();k++)
        {

        pw.println(Db.get(k));
        }
        /*for(int k=0; k<n;k++)
        {
      for(int j=0; j<m;j++)
        pw.println(GainMatrix[k][j]);
       }*/
        pw.println(n);
        pw.println(m);
        pw.println(m);
        pw.println(m);
pw.close();

and this is what I get in the java console:

0   0   0   0   1   0
   0   0   0   0   0   1
   0   1   0   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   1   0   0   0
Initial
propagators: 24
branchers:   1
Summary
runtime:      1.735 (1735.000 ms)
solutions:    48
propagations: 1715
nodes:        153
failures:     29
restarts:     0
peak depth:   7
peak memory:  13 KB

I want to put this matrix in a java code matrix (matrix type res1 = new int [n] [m]) after the reception and I do not know how to do it ??,,

you have an idea about that?? thank you very much for your help

You can read whole lines one at a time from the console into a String, then use the String split method to split the line into an array of strings, each containing one value from the input string (the blanks are used to split the string, then discarded). You can then loop thru that array converting each value from string to int and putting it into your res1 array.

commented: 5 +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.