This website is preserved for historical and scholarly reference and is no longer actively maintained.
QUIZ 29
October 31, 1997
Given the Java statement:
int [ ] v = { 11, 4, 9, ... };
write a segment of Java code that will count the number of times the integer zero occurs in the array v. For example, if v was declared by
int [ ] v = { -1, 0, 1, 0, 0, 1, -1, 1 }
the count of the number of zeros would be 3. However, if v was declared by
int [ ] v = { 7, 3, 0, -5, 24, 8, -11, 16, 2, 0 }
the count of the number of zeros would be 2. Store the number of zeros in the integer variable count.
Use v.length to determine the number of entries actually in the array.