fork download
  1. class Demo {
  2. static public void main(String[] args) {
  3. float[][] pesIAlcada = {
  4. {2.4f, 3.1f, 3.07f, 3.7f, 2.7f, 2.9f, 3.2f, 3f, 3.6f, 3.1f},
  5. { 19f, 18.7f, 22f, 24f, 17f, 18.5f, 21f, 20f, 18.7f, 22f, 18f},
  6. { 47f, 48f, 49f, 50f, 51f, 52f, 51.5f, 50.5f, 49.5f, 49.1f, 50f},
  7. {101f, 104f, 106f, 107f, 107.5f, 108f, 109f, 110f, 112f, 103f}
  8. };
  9.  
  10. int fromRow = 0; // Start copying at row0 (1st row)
  11. int toRow = 2; // Copy until row2 (3rd row) <- not included
  12. // This will copy rows 0 and 1 (first two rows)
  13. float[][] pesNeixement = new float[toRow - fromRow][];
  14.  
  15. /* Copy the specified rows */
  16. for (int i = fromRow; i < toRow; i++) {
  17. pesNeixement[i] = new float[pesIAlcada[i].length];
  18. System.arraycopy(pesIAlcada[i], 0, pesNeixement[i], 0,
  19. pesIAlcada[i].length);
  20. }
  21.  
  22. /* For illustration ONLY: print the new array */
  23. System.out.format("'fromRow' = %d%n'toRow' = %d%n", fromRow, toRow);
  24. System.out.format("Copied %d rows starting with row at index %d:%n",
  25. (toRow - fromRow), fromRow);
  26. for (int i = 0; i < pesNeixement.length; i++) {
  27. for (int j = 0; j < pesNeixement[i].length; j++) {
  28. System.out.format("%,5.2f ", pesNeixement[i][j]);
  29. }
  30. System.out.println();
  31. }
  32. }
  33. }
  34.  
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
'fromRow' = 0
'toRow'   = 2
Copied 2 rows starting with row at index 0:
 2.40  3.10  3.07  3.70  2.70  2.90  3.20  3.00  3.60  3.10 
19.00 18.70 22.00 24.00 17.00 18.50 21.00 20.00 18.70 22.00 18.00