CIS5100 Fall 2005 Exam #1, open book, open notes. Name ___________________ 1. Circle True or False (3 pts each). ANSWERS F In Java, 7/2 == 3.5; T 2-3-4*5 == -21; T The following causes a run time error: int a[]; a[0]=0; F If main(String args[]) is passed "hi hi" then args[0] == args[1]; T Integer.parseInt(3+"4") == 34; F String is a primitive type. T int[] is a reference type. F If a is an array, its last element is a[a.length]. T Catching an exception of type X also catches subclasses of X. T This is a syntax error: throw Exception("oops"); 2. Write a method isIn(x, a) that takes an int, x, and array of int, a, of arbitrary size, as arguments and returns true if any elements in the array equal x, and false otherwise. If a is null, then return false. It might be used like this: (25 pts) int a[] = {10, 20, 30}; if (isIn(20, a)); // true if (isIn(40, a)); // false if (isIn(50, null)); // false // ANSWER boolean isIn(int x, int[] a) { if (a == null) return false; for (int i=0; i