Home Java Array counting the 0 in Java

Array counting the 0 in Java

44 second read
0
0
233

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

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app expla…