code: public static int[][] computeFloydAPSP(int costMatrix[][]) {
          int nrow = costMatrix.length;
          int[][] distMatrix = new int[nrow][nrow];
          //logger.debug("Matrix size: " + n);
          for (int i = 0; i < nrow; i++) {
              for (int j = 0; j < nrow; j++) {
                  if (costMatrix[i][j] == 0) {
                      distMatrix[i][j] = 999999999;
                  } else {
                      distMatrix[i][j] = 1;
                  }
              }
          }
          for (int i = 0; i < nrow; i++) {
              distMatrix[i][i] = 0;
              // no self cycle
          }
          for (int k = 0; k < nrow; k++) {
              for (int i = 0; i < nrow; i++) {
                  for (int j = 0; j < nrow; j++) {
                      if (distMatrix[i][k] + distMatrix[k][j] < distMatrix[i][j]) {
                          distMatrix[i][j] = distMatrix[i][k] + distMatrix[k][j];
                          //P[i][j] = k;        // k is included in the shortest path
                      }
                  }
              }
          }
          return distMatrix;
      }
docs: All-Pairs-Shortest-Path computation based on Floyd's
  algorithm {@cdk.cite FLO62}. It takes an nxn
  matrix C of edge costs and produces an nxn matrix A of lengths of shortest
  paths.
  
  @param costMatrix edge cost matrix
  @return the topological distance matrix