// various destructive functions ("procedures") on arrays public class Exercise4b { // replaces in a all elements at positions // from p (inclusive) to q (exclusive) by x public static void fill(char[] a, int p, int q, char x) { int n = a.length; for (int i = p; i < q; i++) { a[i] = x; } } // reverts a public static void revert(int[] a) { int i = 0; int j = a.length-1; while (i < j) { int t = a[i]; a[i] = a[j]; a[j] = t; i = i+1; j = j-1; } } // subtracts from a (an array of natural) numbers the corresponding // elements of b (also an array of natural numbers) but sets // the result to 0, if it would become negative // the return value indicates, if this has happened public static boolean subtract(int[] a, int[] b) { int n = a.length; boolean truncated = false; for (int i=0; i= b[i]) a[i] = a[i]-b[i]; else { a[i] = 0; truncated = true; } } return truncated; } }