1 consider the following pseudocode that simulates rolling a die 5 times do the foll 5346442
1. Consider the following pseudocode that simulates rolling a die 5 times:
Do the following 5 times:
Roll the die.
Add value to total.
Which statement corresponds to rolling the die?
A. die = generator.nextInt(7) – 1; B. die = generator.nextInt(6) + 1; C. die = generator.nextInt(5) + 1; D. die = generator.nextInt(7); 2. A(n) ___ loop is appropriate for a definite number of iterations. A. while B. for C. infinite D. nested 3. Assume that generator has been initialized to an instance of class Random. Which of the following calls returns a random integer between 0 and n inclusive? A. generator.nextInt(n + 1) B. generator.nextInt(n + 1) – 1 C. generator.nextInt(n) D. generator.nextInt(n) + 1 4. Insert a statement to terminate this loop when the end of input is reached. A. done = true; B. done = “Yes”; C. done = “Q”; D. done == true; 5. Consider the following pseudocode for removing dashes from a phoneNumber: For each position of the phone number starting at the beginning Which is the correct if condition for the pseudocode? A. if (phoneNumber.charAt(i) == '-') B. if (phoneNumber.charAt(i).equals('-')) C. if (!phoneNumber.charAt(i).equals('-')) D. if (phoneNumber.charAt(i) != '-') 6. Insert the missing statement in the following investment loop code fragment. A. years–; B. years == years – 1; C. years == years + 1; D. years++; 7. Consider the following pseudocode for constructing the reverse of an input string: For each position of the string starting at the end working backwards Which is the correct loop body for this pseudocode, assuming that reverse has been declared and initialized to the empty string? A. reverse = reverse + input.stringAt(i); B. reverse = input.charAt(i) + reverse; C. reverse = reverse + input.charAt(i); D. reverse = input.charAt(i); |