/* * Aresh Saharkhiz * saharkiz@gmail.com * Associate Professor / Mapua Institute of Technology / Philippines */ using System; // Introduction to Software Testing // Authors: Paul Ammann & Jeff Offutt // Chapter 1, section 1.2, page 12 internal class numZero_class { public static int numZero(int[] arr) { // Effects: If arr is null throw NullPointerException // else return the number of occurrences of in arr int count = 0; // As example in the book points out, this loop should start at 0. for (int i = 1; i < arr.Length; i++) { if (arr[i] == 0) { count++; } } return count; } public static void Main(string[] argv) { // Driver method for numZero // Read an array from standard input, call numZero() int[] inArr = new int[argv.Length]; if (argv.Length == 0) { Console.WriteLine("Usage: java numZero v1 [v2] [v3] ... "); return; } for (int i = 0; i < argv.Length; i++) { try { inArr[i] = Convert.ToInt32(argv[i]); } catch (FormatException) { Console.WriteLine("Entry must be a integer, using 1."); inArr[i] = 1; } } Console.WriteLine("Number of zeros is: " + numZero(inArr)); } }