PreAP Computer Science Quiz 13.01- 02 Take out a piece of paper and PEN. The quiz starts one minute after the tardy bell rings. You will have 30 – 60 seconds per question.
Title the quiz as shown below The quiz starts in ONE minute. Name Period Date Quiz 13.01-02 1. 8. 2. 9. 3. 10. 4. 11. 5. 12. 6. 13. 7. 14. EC.
Question 01 An algorithm is a step-by-step solution to a problem. a mathematical solution to a problem. a program that creates poetry that rhymes. none of the above.
Question 02 The random method of the Expo class is a void class method. a void object method. a return class method. a return object method.
Question 03 The nextInt method of the Random class is a void class method. a void object method. a return class method. a return object method.
Question 04 What will this program segment display if it is executed twice? for (int j = 1; j <= 10; j++) System.out.println(Expo.random(1,1000); (a) 1st Execution: 10 Identical Numbers 2nd Execution: The same 10 Identical Numbers (b) 1st Execution: 10 Different Numbers 2nd Execution: The same 10 Different Numbers (c) 1st Execution: 10 Different Numbers 2nd Execution: A different set of 10 Different Numbers
Question 05 What will this program segment display if it is executed twice? Random rand = new Random(); for (int j = 1; j <= 10; j++) System.out.println(rand.nextInt(1000) + 1); (a) 1st Execution: 10 Identical Numbers 2nd Execution: The same 10 Identical Numbers (b) 1st Execution: 10 Different Numbers 2nd Execution: The same 10 Different Numbers (c) 1st Execution: 10 Different Numbers 2nd Execution: A different set of 10 Different Numbers
Question 06 What will this program segment display if it is executed twice? Random rand = new Random(4600); for (int j = 1; j <= 10; j++) System.out.println(rand.nextInt(1000) + 1); (a) 1st Execution: 10 Identical Numbers 2nd Execution: The same 10 Identical Numbers (b) 1st Execution: 10 Different Numbers 2nd Execution: The same 10 Different Numbers (c) 1st Execution: 10 Different Numbers 2nd Execution: A different set of 10 Different Numbers
Question 07 What will this program segment display if it is executed twice? Random rand = new Random(4600); int x = rand.nextInt(1000) + 1; for (int j = 1; j <= 10; j++) System.out.println(x); (a) 1st Execution: 10 Identical Numbers 2nd Execution: The same 10 Identical Numbers (b) 1st Execution: 10 Different Numbers 2nd Execution: The same 10 Different Numbers (c) 1st Execution: 10 Different Numbers 2nd Execution: A different set of 10 Different Numbers
Question 08 Random rand = new Random(4600); Which part of the statement below is the random seed? Random rand = new Random(4600); rand new 4600 The 1st Random The 2nd Random
Question 09 Random rand = new Random(); What is the output of this program segment? Random rand = new Random(); System.out.println(rand.nextInt(5000)); a random number between 0 and 5000 a random number between 0 and 4999 a random number between 1 and 5000 a random number between 1 and 4999 a random number between 1 and 5001
Question 10 Random rand = new Random(); What is the output of this program segment? Random rand = new Random(); System.out.println(rand.nextInt(5000) + 1); a random number between 0 and 5000 a random number between 0 and 4999 a random number between 1 and 5000 a random number between 1 and 4999 a random number between 1 and 5001
Question 11 Random rand = new Random(); What is the output of this program segment? Random rand = new Random(); System.out.println(rand.nextInt(301) + 500); a random number between 300 and 500 a random number between 301 and 500 a random number between 301 and 801 a random number between 500 and 800 a random number between 500 and 801
Question 12 Random rand = new Random(); Which of the following statements can replace the mystery code to display a random # from 0 to 400? Random rand = new Random(); System.out.println( mystery code ); rand.nextInt(399) rand.nextInt(400) rand.nextInt(399) + 1 rand.nextInt(400) + 0 rand.nextInt(401)
Question 13 Random rand = new Random(); Which of the following statements can replace the mystery code to display a random # from 30 to 70? Random rand = new Random(); System.out.println( mystery code ); rand.nextInt(30) + 70 rand.nextInt(70) + 30 rand.nextInt(40) + 30 rand.nextInt(41) + 30 rand.nextInt(41) + 70
Question 14 Random rand = new Random(); Which of the following statements can replace the mystery code to display a random 5-digit number? Random rand = new Random(); System.out.println( mystery code ); rand.nextInt(99999) + 10000 rand.nextInt(10000) + 99999 rand.nextInt(90000) + 10000 rand.nextInt(89999) + 10000 rand.nextInt(100000)
Extra Credit Random rand = new Random(); What is the output of this program segment? Random rand = new Random(); System.out.println(rand.nextInt(21) – 10); a random number between -10 and 21 a random number between -21 and 10 a random number between -10 and 10 a random number between -21 and 21 a random number between -10 and 9 17