
C Sc 227 Practice Quiz SL _______________ Name ___________________________ 50pts
1. Complete the output that would be generated by this code (8pts)
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(12);
list.add(23);
list.add(-5);
list.add(-5);
list.add(12);
Collections.sort(list);
for (Integer theNextInt : list)
System.out.print(theNextInt + " ");
System.out.println("=================");
System.out.println(list.contains(-5));
System.out.println(list.contains(9999));
System.out.println(Collection.min());
System.out.println(Collections.binarySearch(list, 23));
System.out.println("=================");
Collections.reverse(list);
for (Integer theNextInt : list)
System.out.print(theNextInt + " ");
2. Complete the code that reads all integers from the file named "numbers" (assume it's found) and prints
how many integers were found (assume numbers only has integers) and the range. The output should be
Count: 18
Range: 17
the file "numbers"
try {
Scanner scanner = new Scanner(new File("numbers");
}
catch (FileNotFoundException fnfe) {
System.out.println("the file 'numbers' was niot found");
}
int range;
int count
// Complete the code
System.out.println("Count: " + count);
System.out.println("Range: " + range);
Add output here
=================
=================
4 -3 2 1
9 11
6 14 9 12 9
-1 0 5 6
0 1 7