Final Preparation: Practice Questions (Quizzes & Tests)

¡Supera tus tareas y exámenes ahora con Quizwiz!

c) C

Given the following code, what is output by the method call, mystery (5, 7.0015)? a) A b) B c) C d) D

c) 3 4

Given the method below, what is the output to the console with a call of mystery(48)? a) 12 2 b) 6 3 c) 3 4 d) 1 5 e) Compiler error

b) choice.equals("yes")

Consider the code below which has a missing test in the if statement. What is the appropriate test to check for user entering "yes" as the input string? a) choice == "yes" b) choice.equals("yes") c) choice = "yes" d) choice == String "yes"

c) 50 - 69

Consider the code below. What range of values can the variable number have? a) 0 - 19 b) 0 - 20 c) 50 - 69 d) 0 - 70

b) g.fillRect(10, 10, 50, 50);

Consider the code segment below. What line of code is missing if you want to draw a solid, black square that has a side length of 50 pixels and starts at (10, 10)? a) panel.fillSquare(10, 10, 50) b) g.fillRect(10, 10, 50, 50); c) g.fillRect(10, 10, 50) d) panel.fillRect(10, 10, 50, 50);

b) Hello George

Consider the following code and execution where the user inputs "George Washington" after the prompt. What is the output of the program? a) Hello George Washington b) Hello George c) Hello Washington d) Hello

b) A-c-a-d-e-m-y

Consider the method printLetters below. What is the output to the console with a call to the method of printLetters("Academy")? a) Academy b) A-c-a-d-e-m-y c) A-c-a-d-e-m-y- d) -A-c-a-d-e-m-y

b) void method1 (int a) {}

Consider these two overloaded versions of method1(). Which of them will be called when the statement below is executed? method1(222); a) void method1 (long a) {} b) void method1 (int a) {}

d) if y == 0 is true it doesn't evaluate x * y > 10

Considering the following code, which option is an example of short circuit evaluation? if ( y == 0 || x * y > 10 ) a) if x * y > 10 is false it evaluates y == 0 b) if x * y > 10 is false it doesn't evaluate y == 0 c) if y == 0 is false it doesn't evaluate x * y > 10 d) if y == 0 is true it doesn't evaluate x * y > 10 e) if y == 0 is false it evaluates x * y > 10

a) true

The method indexOf(",") will allow you to search for the location of a comma in a String. a) true b) false

Undefined. The variable m is out of scope once the for-loop is complete.

What is the value of m after you exit the loop?

a) j <= 5

What must the test be so that the following fragment prints out the integers -5 through and including 5? a) j <= 5 b) j == 5 c) j > 5 d) j < 5

WXYZ

What output is produced by the following code segment?

c) GREENJEANS

What output is produced by the following code segment? a) No output b) BLUE c) GREENJEANS d) BLUEJEANS e) JEANS f) BLUEGREENJEANS

c) Pass by value

What type of parameter passing is used by Java? a) Pass by parameter b) Pass by reference c) Pass by value d) Pass by object

b) ABBA

What will be the output of the following code? a) abba b) ABBA c) ab ba d) AB BA

b) x >= y || w != z

Which boolean expression is the same as this expression: ! ( x < y && w == z) a) x <= y && w == z b) x >= y || w != z c) x <= y || w != z d) x <= y && w != z e) x < y && w != z

a) if ( letter == 'J' )

Which if statement below tests if the variable letter holds J? (letter is a char) a) if ( letter == 'J' ) b) if ( letter == J ) c) if ( letter >= 'J' ) d) if ( letter == "J" ) e) if ( letter = 'J' )

b) None of these (double negative - meaning a String can contain all of the above)

Which of the following can a String NOT contain? a) words b) None of these (double negative - meaning a String can contain all of the above) c) characters d) digits e) symbols (like %)

e) Convert double values to ints and do calculations using integers

What is the best way to avoid round-off error? a) Do all calculations using doubles. b) Use booleans for calculations. c) Convert int values to doubles and do calculations using doubles. d) Convert double values to ints and do calculations using integers. e) Convert char values to doubles and do calculations using doubles.

30 26 22 18 14 10 6 2

What is the output of the following code fragment?

I love Java! Coding is fun! I love Java! Coding is fun! I love Java! Coding is fun! I love Java! Coding is fun! I love Java! Coding is fun!

What is the output of the following code fragment?

d) 0 2 4 6 8 10 12 14 16 18 20

What is the output of the following code fragment? a) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 b) 0 2 4 6 8 10 12 14 16 18 c) 0 2 4 6 8 10 d) 0 2 4 6 8 10 12 14 16 18 20

d) 0 1 2 3 4 5 6 7 8 9

What is the output of the following code fragment? a) 1 2 3 4 5 6 7 8 9 b) 0 1 2 3 4 5 6 7 8 c) 0 1 2 3 4 5 6 7 d) 0 1 2 3 4 5 6 7 8 9

b) d

What is the output of the following code segment? a) o b) d c) c d) e

d) 0 1 2 3 4 5

What is the output of the following code? a) 0 1 2 3 4 5 6 7 8 9 10 b) 1 2 3 4 5 c) 1 2 3 4 5 6 7 8 9 10 d) 0 1 2 3 4 5 e) Compiler error

d) Compiler error

What is the output of the following code? a) 01234567890123456789012345678901234567890123456789 b) 123456789123456789123456789123456789123456789 c) 12345678901234567890123456789012345678901234567890 d) Compiler error

a) 97.6

What is the output of the following code? a) 97.6 b) -97.6 c) 98 d) -98 e) -96

a) one

What is the output of the following code? a) one b) two c) three d) four e) five

d) 40

What is the output of the following program? a) compiler error b) 20 c) 0 d) 40

c) issi

What is the output of the following program? a) sissi b) sississippi c) issi d) issip

c) method overloading

What is the process of defining two or more methods within the same program that have the same name but different parameter declarations? a) None of those mentioned b) method hiding c) method overloading d) method overriding

b) public static final double GRAVITY = 9.8;

What is the proper syntax for declaring a class constant for gravitational acceleration? a) public static void double GRAVITY = 9.8; b) public static final double GRAVITY = 9.8; c) public static final int GRAVITY = 9.8; d) public final double GRAVITY = 9.8;

c) Scanner console = new Scanner(System.in);

What is the proper syntax to create an object called console to read input from the keyboard? a) console = new Scanner(System.in); b) Scanner console = new Scanner(keyboard); c) Scanner console = new Scanner(System.in); d) Scanner = new console (keyboard);

d) 12

What is the result of executing the following code: a) Syntax error b) Runtime error c) 10 d) 12

f) All three loops

What is the scope of the variable var1? a) Loop #1 b) Loop #2 c) Loop #3 d) Loop #1 and Loop #2 e) Loop #2 and Loop #3 f) All three loops

d) Loop #1 and Loop #2

What is the scope of the variable var2? a) Loop #1 b) Loop #2 c) Loop #3 d) Loop #1 and Loop #2 e) Loop #2 and Loop #3 f) All three loops

a) for (int i = 5; i = 10; i++)

Which for loop will not execute? a) for (int i = 5; i = 10; i++) b) for (int i = 0; i > -5; i--) c) for (int i = 5; i <= 10; i++) d) for (int i = 0; i < 5; i++)

d) !console.hasNextInt( )

The code below is designed to keep prompting the user to enter their age until an integer is entered. What is the missing code to make this code work as intended? a) console.hasNextInt() b) console.hasNext() c) console.nextInt() d) !console.hasNextInt( )

d) II only

The following if statement tests the rainfall in New York's Central Park during the months of June, July and August. It could be replaced with... a) II or III b) III only c) I only d) II only e) I, II or III

b) The x++ needs to be x += 2 and the x < 26 needs to be <=

The following loop is intended to print the even numbers from 20 to 26. What would you need to change in order for the code to work correctly? a) The x++ needs to be x += 2 b) The x++ needs to be x += 2 and the x < 26 needs to be <= c) The x < 26 needs to be <= d) It needs an if statement: if (x % 2 == 0) e) Nothing, the code works as written.

b) return (cents % 5 != 0);

The method hasPennies accepts the number of cents as a parameter and returns whether or not pennies are required. What line of code could replace everything highlighted in blue? a) return (cents % 5 == 0); b) return (cents % 5 != 0); c) return (cents / 5 >= 0); d) return (cents % 1 == 0);

c) while (number > 0);

The method zeroDigits accepts an integer as a parameter and returns the number of digits in the number that are zero. For example, the call zeroDigits(50340) returns 2. What is the missing code that completes the method? a) until (number >= 0); b) else if (number >= 0); c) while (number > 0); d) if (number > 0);

b) 2

What is output to the screen by the following code? a) 4 b) 2 c) 5 d) 3 e) 1

b) num += 2

Fill in the blank so that the following adds up the odd numbers from 1 to 99 a) num-- b) num += 2 c) j++ d) num+2

a) 8 9 1 0

What is output to the screen by the following code? a) 8 9 1 0 b) 198 19 1 0 c) 19 1 0 0 d) 7 8 9 1 e) The loop will not terminate

a) 100

How many times is the println statement executed? a) 100 b) 20 c) 45 d) 10

c) import java.awt.*;

22. What line of code must be included above the class header in order to code graphics in Java? a) import java.graphics.*; b) import graphics; c) import java.awt.*; d) include graphics.java;

b) a local variable

A variable defined inside a method is referred to as ________ a) a global variable b) a local variable c) a method variable d) a block variable

a) String val = scan.nextLine();

Assuming that scan is a properly initialized Scanner variable, which of the following correctly inputs a String? a) String val = scan.nextLine(); b) String val = scan.nextDouble(); c) String val = scan.nextInt(); d) String val = scan.nextValue(); e) String val = nextDouble();

a) It can return the value to the caller using a return statement

How can a method communicate a primitive value back to the caller? a) It can return the value to the caller using a return statement b) It can assign the value to one of its parameters c) A method can never communicate with its caller by any means d) It can call its caller with the correct value

e) Infinite loop

How many times will the following loop repeat? a) 20 b) 21 c) 22 d) 23 e) Infinite loop

a) No, because all the method has is a copy of its caller's values

If a method assigns a new value to a primitive parameter, will this have any effect on its caller? a) No, because all the method has is a copy of its caller's values b) Yes, because the method and its caller share the same section of memory c) Yes, the change will affect the matching value inthe caller d) No, because the method is not allowed to change the value of any parameter

a) control is returned to method C

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens? a) control is returned to method C b) the program terminates c) control is returned to method B d) control is returned to method A

d) int

In the following method declaration, what is the return type? public static int myMethod (int count, double value) { return 4; } a) double b) 4 c) myMethod d) int e) count f) void

a) 0

In the following method how many values are returned? public static void syncPhone (int idNumber) { } a) 0 b) 1 c) 2

d) System.out.printf("Average = %.2f", avg);

Suppose that a variable avg is declared as double with the value of 7.125. What line of code would result in the desired output of "Average = 7.13"? a) System.out.println("Average = " + avg); b) System.out.println("Average = %.2f", avg); c) System.out.printf("Average = %f", avg); d) System.out.printf("Average = %.2f", avg);

a) >=, &&, <=

To test if a grade is a C (between 70 and 79 inclusive) you would use the following if statement with which three sets of symbols correctly fill in the blanks? a) >=, &&, <= b) >=, ||, <= c) >, ||, < d) <, &&, > e) <, ||, >

c) Making decisions

What are if statements used for in programs? a) Storing data b) Repeating commands c) Making decisions d) Numeric casts e) Numeric calculations

d) First: 16 Last: 30

What are the first and last numbers printed after running the code below? a) First: 15 Last: 29 b) First: 15 Last: 30 c) First: 16 Last: 29 d) First: 16 Last: 30 e) First: 16 Last: 28

d) Prints a message if month is 4 and day is less than or equal to 21

What does the following code do? a) Doesn't work - you cannot have two if statements together. b) Prints a message if month is 4 or day is greater than or equal to 21. c) Prints a message if month is 4 and day is less than or equal to 21. d) Prints a message if month is 4 and day is greater than or equal to 21. e) Prints a message if month is 4 or day is less than or equal to 21.

a

What does the following print to the console?

c) The value that is passed into a method by a caller

What is a parameter? a) A variable used to control a counting loop b) The value that is returned by a method c) The value that is passed into a method by a caller


Conjuntos de estudio relacionados

GY121 - The Ecological Footprint

View Set

Eighteenth- Century Classicism #4

View Set

Emergency Preparedness Response Course (EPRC) - Clinician Course (8 hrs) & Operator Course (8hrs)

View Set

Chapter 30 Management of Patients with Hematologic Neoplasms

View Set