Search
 
SCRIPT & CODE EXAMPLE
 

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Sending String from one activity to another 
Java :: Java system load from resources 
Java :: display two dimensional array java 
Java :: using a SnackBar on androidstudio 
Java :: java xml element get attribute value 
Java :: how to convert string hashcode to color in java android 
Java :: compress a directory in java 
Java :: android activity keyboard hide 
Java :: make quotation a string 
Java :: binary tree level traversal 
Java :: arraylist remove name in java 
Java :: intellij set target bytecode version 
Java :: return class name java 
Java :: map.keyset 
Java :: how to sort arraylist in java 
Java :: java noverify 
Java :: inheritance in java 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message) 
Java :: kotlin edittext default value 
Java :: seek bar 
Java :: hashmap put method 
Java :: 2048 java code 
Java :: java stream loop through list 
Java :: java add two arrays together 
Java :: java encapsulation 
Java :: declaration in java 
Java :: list interface java 
Java :: easter egg 
Java :: android how to know when snackbar is done 
Java :: is it possible to declare two conditions in for loop in javascrip 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =