genrate a working logic form this ;
package com.elqassmirida1;


import java.util.LinkedList;
import java.util.PriorityQueue;

public class Convex {
//    private final Integer[][] table=new Integer[][]{
//            {0,1,0,0,0},
//            {1,0,1,0,0},
//            {0,0,0,1,0},
//            {0,0,0,0,1},
//            {0,0,0,1,0}};

    private final Integer[][] table  = new Integer[][]{
            {1/2,1/2,0,0,0,0},
            {2/3,1/3,0,0,0,0},
            {0,0,1/2,1/2,0,0},
            {0,0,0,0,1,0},
            {0,0,0,1,0,0},
            {0,0,1,0,0,0}
    };

    public void calculateFermutureDeTransition(){
        Integer[][] transposedArray = transposeMatrix();
        for(int j=0;j<table.length;j++){
            LinkedList<Integer> visited1 = forwardPass(j,table);
            LinkedList<Integer> visited2 = backwardPass(j,table);
            //visited = 0;
            //LinkedList<Integer> visited2 = forwardPass(j,transposedArray);
            //
            System.out.println("for n="+j);
            System.out.println("forward pass result is "+visited1);

            System.out.println("backward pass result is "+visited2);

            LinkedList<Integer> result = new LinkedList<Integer>();
            for(int i=0;i<visited1.size();i++){
                if(visited2.contains(visited1.get(i))){
                    result.add(visited1.get(i));
                }

            }
            System.out.println("sous graph fortement Connect is "+result);
        }

    }

    public LinkedList<Integer> forwardPass(int n, Integer[][] table) {
        LinkedList<Integer> visited = new LinkedList<Integer>();
        PriorityQueue<Integer> pile = new PriorityQueue<>();

        pile.add(n);
        int i = n;
        while (!pile.isEmpty()) {
            i = pile.poll();
            visited.add(i);
            //for i = 0 we have [0,1,0,0,0]

            //to populate the pile with all possible connection arcs
            for (int j = 0; j < this.table[i].length; j++) {
                //if there is an arc between i and j and j is not visited yet
                if (this.table[i][j] != 0 && !visited.contains(j)) {
                    pile.add(j);

                }

            }
        }
        return visited;
    }

    public LinkedList<Integer> backwardPass(int n, Integer[][] table) {
        LinkedList<Integer> visited = new LinkedList<Integer>();
        PriorityQueue<Integer> pile = new PriorityQueue<>();
        pile.add(n);
        int j = n;
        while (!pile.isEmpty()) {
            j = pile.poll();
            visited.add(j);

            //to populate the pile with all possible connection arcs
            for (int i = 0; i < this.table[j].length; i++) {
                //if there is an arc between i and j and j is not visited yet
                if (this.table[i][j] != 0   && !visited.contains(i)) {
                    pile.add(i);

                }

            }
        }
        return visited;
    }

    public Integer[][] transposeMatrix() {
        Integer[][] transposed = new Integer[table[0].length][table.length];
        for (int i = 0; i < table.length; i++) {
            for (int j = 0; j < table[0].length; j++) {
                transposed[j][i] = table[i][j];
            }
        }
        return transposed;
    }

}