Home Java Array counting the 0 in Java

Array counting the 0 in Java

44 second read
0
0
202

Create a 10 element integer array and store some integer values display as the counting of 0.

public class JavaEx {
    public static void main(String args[]) {

        int numbers[] = {10,15,0,0,6,0,0,1,6,4};
        int x,count,len;

        count = 0;
        len = numbers.length;

        for(x= 0; x < len; x++)
        {
            if(numbers[x]==0)
            {
                System.out.println(numbers[x]);
                count++;
            }
        }
        System.out.println(count);
    }

}

above examples  int numbers[] = {10,15,0,0,6,0,0,1,6,4};  here there is 4 zeros.

Output display as

0
0
0
0
4

 

Load More Related Articles
Load More By admin
Load More In Java

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Laravel 11 CRUD Mastering RESTful API MVC with Repository Pattern

In this tutorial will teach Laravel 11 Api MVC with Repository Pattern Crud Application st…