/* * Aresh Saharkhiz * saharkiz@gmail.com * Associate Professor / Mapua Institute of Technology / Philippines */ using System; // Introduction to Software Testing // Authors: Paul Ammann & Jeff Offutt // Chapter 5, section 5.2, page 189 internal class sum_class { //Effects: If x null throw NullPointerException // else return the sum of the values in x public static int sum(int[] x) { int s = 0; for (int i = 0; i < x.Length; i++) { s = s + x[i]; // s = s - x[i]; } return s; } public static void Main(string[] argv) { // Driver method for sum // Read an array from standard input, call sum() 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("The sum is: " + sum(inArr)); } }