QUESTION 1



University Interscholastic League

Computer Science Competition

Number 105 (Regional - 2007)

General Directions (Please read carefully!):

1) DO NOT OPEN EXAM UNTIL TOLD TO DO SO.

2) No calculators of any kind may be used.

3) There are 40 questions on this contest exam. You have 45 minutes to complete this contest. If you are in the process of actually writing an answer when the signal to stop is given, you may finish writing that answer.

4) Papers may not be turned in until 45 minutes have elapsed. If you finish the test before the end of the allotted time, remain at your seat and retain your paper until told to do otherwise. You may use this time to check your answers.

5) All answers must be written on the answer sheet/Scantron card provided. Indicate your answers in the appropriate blanks provided on the answer sheet or on the Scantron card. Clean erasures are necessary for accurate Scantron grading.

6) You may place as many notations as you desire anywhere on the test paper, but not on the answer sheet or Scantron card which are reserved for answers only.

7) You may use additional scratch paper provided by the contest director.

8) All questions have ONE and only ONE correct (BEST) answer. There is a penalty for all incorrect answers. All provided code segments are intended to be syntactically correct, unless otherwise stated. Ignore any typographical errors and assume any undefined variables are defined as used.

9) A reference to commonly used Java classes is provided at the end of the test, and you may use this reference sheet during the contest. You may detach the reference sheets from the test booklet, but do not do so until the contest begins.

10) Assume that any necessary import statements for standard Java 2 packages and classes (e.g. .util, System, Math, Double, etc.) are included in any programs or code segments that refer to methods from these classes and packages.

Scoring:

1) All questions will receive 6 points if answered correctly; no points will be given or subtracted if unanswered; 2 points will be deducted for an incorrect answer.

|Question 1 | |E |

| | |

| |What is the sum of BC16 and 1516? |

| |A. |110100012 |B. |

| |What is output by the code to the right? | |

| |A. |3 |B. |13 |C. |6 | |

| |D. |3.33333 |E. |16 | |

|Question 3 | |B |int n = 20; |

| | | |int total = 0; |

| | | |for(int i = 1; i = z ) | |

| |A. |!(x + y < z) && !( x * y >= z) | |

| |B. |x + y < z || x * y >= z | |

| |C. |x + y >= z || !(x * y >= z) | |

| |D. |!( x + y >= z) || !(x * y < z) | |

| |E. |More than one of these. | |

|Question 9 | |B |int x2 = 100; |

| | | |int y2 = 77; |

| | | |int z2 = y2 / x2; |

| | | |System.out.print( z2 + "_" + x2 ); |

| |What is output by the code to the right? | |

| |A. |0.77_100 |B. |77_100 |C. |0_23 | |

| |D. |0_100 |E. |There is no output due to a syntax | |

| | | | |error. | |

|Question 10 | |B |public static void ht(int x, int y){ |

| | | |x = x ^ y; |

| | | |y = y ^ x; |

| | | |x = y ^ x; |

| | | |System.out.print( x + "_" + y ); |

| | | |} |

| |What is output by the method call ht(17, 31) ? | |

| |A. |31_17 |B. |0_0 |C. |17_31 | |

| |D. |x_y |E. |The output cannot be predicted due to | |

| | | | |overflow of the variables. | |

|Question 11 | |B | |

| | | |public interface Bike{ |

| | | |public int wheels(); |

| | | |public String toString(); |

| | | |} |

| | | | |

| | | |------------------------------------------ |

| | | | |

| | | |public abstract class Vehicle{ |

| | | | |

| | | |public abstract boolean humanPower(); |

| | | | |

| | | |public void show(){ |

| | | |System.out.print( type() ); |

| | | |} |

| | | | |

| | | |private String type(){ |

| | | |return "vehicle"; |

| | | |} |

| | | | |

| | | |public String toString(){ |

| | | |return "engine:" + !humanPower(); |

| | | |} |

| | | |} |

| | | | |

| | | |------------------------------------------ |

| | | | |

| | | |public class MountainBike extends Vehicle |

| | | |implements Bike{ |

| | | | |

| | | |private int myGears; |

| | | | |

| | | |public MountainBike(int gears){ |

| | | |myGears = gears; |

| | | |} |

| | | | |

| | | |public boolean humanPower(){ |

| | | |return true; |

| | | |} |

| | | | |

| | | |public int wheels(){ |

| | | |return 2; |

| | | |} |

| | | | |

| | | |public String type(){ |

| | | |return "mountain"; |

| | | |} |

| | | | |

| | | |public int grs(){ |

| | | |return myGears; |

| | | |} |

| | | |} |

| |Which of the following statements will not cause | |

| |a syntax error? | |

| |I. Vehicle v = new Vehicle(); | |

| |II. Bike b1 = new Vehicle(); | |

| |III. Bike b2 = new MountainBike(14); | |

| |A. |I only |B. |II only |C. |III Only | |

| |D. |I and III |E. |II and III | |

|Question 12 | |D | |

| |What is output by the following code? | |

| |MountainBike m1 = new MountainBike(10); | |

| |System.out.print( m1.grs() + "_" + m1 ); | |

| |A. |10_engine:true | |

| |B. |2_engine:true | |

| |C. |10_engine: | |

| |D. |2_engine: | |

| |E. |10_engine:false | |

|Question 13 | |B | |

| |What is output by the following code? | |

| |MountainBike m2 = new MountainBike(10); | |

| |m2.show(); | |

| |A. |mountain |B. |m2 |C. |engine: | |

| |D. |10 |E. |vehicle | |

|Question 14 | |D | |

| |What is output by the following code? | |

| |Vehicle v1 = new MountainBike(10); | |

| |System.out.print( v1 ); | |

| |int val = ((MountainBike)v1).grs(); | |

| |System.out.print( val ); | |

| |A. |engine:false10 | |

| |B. |engine: | |

| |C. |engine:10 | |

| |D. |There is no output due to a syntax error. | |

| |E. |There is no output due to a runtime error. | |

|Question 15 | |D |int div = 2; |

| | | |double a = 5 / div + 1.5 + 7 / (div * 2); |

| | | |System.out.println( a ); |

| |What is output by the code to the right? | |

| |A. |4.5 | |

| |B. |5.0 | |

| |C. |5 | |

| |D. |5.75 | |

| |E. |5.25 | |

|Question 16 | |B |//pre: n >= 0 |

| | | |public static void change(int n){ |

| | | |if( n = 0; j--){ |

| | | |list.add( j + inc ); |

| | | |inc += 3; |

| | | |} |

| | | |Iterator it = list.iterator(); |

| | | |while( it.hasNext() ){ |

| | | |if( it.next() > 10 ) |

| | | |System.out.print( it.next() ); |

| | | |} |

| |What is output by the code to the right? | |

| |A. |11131517 | |

| |B. |17151311 | |

| |C. |1115 | |

| |D. |91115 | |

| |E. |1317 | |

|Question 31 | |D |ArrayList kd = new |

| | | |ArrayList(); |

| | | |int[] data = {1, 4, 1, 7, 20, 2, 33}; |

| | | |for(int el : data){ |

| | | |if( el < kd.size() ) |

| | | |kd.add(el, el); |

| | | |else if( el < 20 ) |

| | | |kd.add(el); |

| | | |else |

| | | |kd.add(0, el); |

| | | |} |

| | | |for(int el : kd) |

| | | |System.out.print( el ); |

| |What is output by the code to the right? | |

| |A. |141720233 | |

| |B. |3312 | |

| |C. |332072411 | |

| |D. |332012147 | |

| |E. |3317 | |

|Question 32 | |B |/* pre: list != null, list.length > 0, |

| | | |list is sorted in ascending order. |

| | | |*/ |

| | | |public static int myst(int[] lt, int tgt){ |

| | | | |

| | | |int len = lt.length; |

| | | |if( tgt < lt[0] || tgt > lt[len - 1] ) |

| | | |return -1; |

| | | | |

| | | |int pos = tgt - lt[0]; |

| | | |pos *= len - 1; |

| | | |pos /= lt[len - 1] - lt[0]; |

| | | |int inc = lt[pos] < tgt ? 1 : -1; |

| | | | |

| | | |while( pos >= 0 && pos < len && |

| | | |lt[pos] != tgt){ |

| | | | |

| | | |pos += inc; |

| | | |} |

| | | | |

| | | |pos = (pos == len) ? -1 : pos; |

| | | |return pos; |

| | | |} |

| |What is output by the following code? | |

| |int[] dt = {0, 1, 2, 3, 4, 10}; | |

| |System.out.print( myst(dt, 1) ); | |

| |A. |0 |B. |1 | |

| |C. |-1 |D. |10 | |

| |E. |There is no output due to a runtime error. | |

|Question 33 | |B | |

| |What is output by the following code? | |

| |int[] dt = {1, 0, 3, 4, 2}; | |

| |System.out.print( myst(dt, 3) ); | |

| |A. |-1 |B. |0 | |

| |C. |1 |D. |2 | |

| |E. |There is no output due to a runtime error. | |

|Question 34 | |D | |

| |Which of the following best describes the function of method myst? | |

| |A. |Count the number of elements in lt equal to tgt. | |

| |B. |Sort the array lt. | |

| |C. |Search the array lt for tgt. | |

| |D. |Find the maximum value in the array lt. | |

| |E. |Find the minimum value in the array lt. | |

|Question 35 | |D | |

| | | |char c; |

| | | |Map m = |

| | | |new TreeMap(); |

| | | | |

| | | |String names = "ROB_BOB_BRAD_DAD_BROOD"; |

| | | | |

| | | |for(int i = 0; i < names.length(); i++){ |

| | | |c = names.charAt(i); |

| | | |if( Character.isLetter(c) ){ |

| | | |if( m.containsKey(c) ) |

| | | |m.put( c, m.get(c) + 1 ); |

| | | |else |

| | | |m.put( c, 1 ); |

| | | |} |

| | | |} |

| | | | |

| | | |Set st = m.keySet(); |

| | | |for( Character k : st ) |

| | | |System.out.print( m.get(k) ); |

| |What is output by the code to the right? | |

| |A. |254434 | |

| |B. |25443 | |

| |C. |ABDOR | |

| |D. |34524 | |

| |E. |There is no output due to a runtime error. | |

|Question 36 | |D |public class Structure2{ |

| | | | |

| | | |private ArrayList myCon; |

| | | | |

| | | |//pre: h > 0 |

| | | |public Structure2(int h){ |

| | | |myCon = new ArrayList(); |

| | | |for(int i = 0; i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download