Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

count true in matrix java

public class CountTrue {
    public static void main(String[] args){
        boolean[][]mat= {
                {false, false,true},
                {true, true, false},
        };
        int counter=0;
        for (int row = 0; row <mat.length ; row++) {
            for (int col = 0; col < mat[0].length; col++) {
                boolean currentElement = mat [row][col];
                if (currentElement){
                    counter++;

                }
            }
        }
        System.out.println(counter);
    }
}
 
PREVIOUS NEXT
Tagged: #count #true #matrix #java
ADD COMMENT
Topic
Name
3+4 =