CSC200 Final Exam Practice Questions and Answers | Complete Solution
CSC200 Final Exam Practice Questions and Answers | Complete Solution . which of the following statements is false? - Answer It assigns the value of number1 to sum. Java's predefined classes are grouped into ________. - Answer packages Optional parentheses in expressions are said to be _________. - Answer redundant Portions of statements that contain calculations are called ________. - Answer expressions Programs remember numbers and other data in the computer's memory and access that data through program elements called ________. - Answer variables The body of each class declaration begins with ________ and ends with ________. - Answer {, } The filename for the public class that begins with public class Addition must be ________. - Answer A The format specifier ________ is a placeholder for an int value. - Answer %d What is the value of result after the following Java statements execute (assume all variables are of type int)? a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; - Answer 119 What will be output after the following Java statements have been executed (assume all variables are of type int)? a=4; b=12; c= 37; d= 51; if(ab) print if(ab) print if(d=c) print if (c!=d) print - Answer ab c!=d When method printf requires multiple arguments, the arguments are separated with ________. - Answer commas (,) Which command compiles the Java source code file W? - Answer javac W Which command executes the Java class file W? - Answer java Welcome Which is the output of the following statements? print ("Hello"); println("World"); - Answer Hello World Which of the following escape sequences represents a carriage return? - Answer r Which of the following is a variable declaration statement? - Answer int total; Which of the following is a Scanner method for inputting an integer value? - Answer nextInt Which of the following is the escape character? - Answer Which of the following is not a Java primitive type? - Answer real Which of the following is not a compilation error? - Answer Placing a semicolon at the end of the first line of an if statement. Which of the following is not a valid Java identifier? - Answer my Value Which of the following statements does not alter the value stored in a memory location? - Answer int a; Which of the following statements is false? - Answer Variable name identifiers must begin with a lowercase letter. Which of the following statements is true? - Answer All of these are true. (package, class names, enter your age) Which of the following statements would display the phrase Java is fun? - Answer Sln("hellois funrJava "); How many times is the body of the loop below executed? int c = 1; while (c20) c--; - Answer 0 In an expression containing values of the types int and double, the ________ values are ________ to ________ values for use in the expression. - Answer int, promoted, double Local variables must be ________. - Answer initialized before their values are used in an expression Sentinel-controlled repetition is also known as ________. - Answer indefinite repetition The empty statement is denoted by what symbol? - Answer parentheses () What does the expression x %= 10 do? - Answer Divides x by 10 and stores the remainder in x. Which of the following is a double-selection control statement? - Answer if...else Which of the following is not a Java keyword? - Answer next Which of the following is not a control structure? - Answer declaration structure Which of the following is not a primitive type? - Answer String Which of the following operators associates from left to right? - Answer / Which of the following statements about the conditional operator (?:) is false? - Answer The second operand is the result value if the condition evaluates to false. Which of the following statements is false? - Answer Cast operators associate from right to left and are one level lower in precedence than the multiplicative operators. Which of the following statements is true? - Answer Syntax errors are caught by the compiler. Logic errors have effects at execution time. Consider the following two Java code segments: - Answer Both The output from these segments is not the same and The scope of the control variable i is different for the two segments are true. Counter-controlled repetition requires ________. - Answer all of these The control variable of a counter-controlled loop should be declared as ________ to prevent errors. - Answer int To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a ________. - Answer break statement Which expression is equivalent to if (!(grade == sentinelValue))? - Answer if (grade != sentinelValue) Which formatting flag indicates that the floating-point values should be output with a thousands separator? - Answer comma (,) Which of the following is equivalent to this code segment? - Answer int total = 0; for (int i = 0; i = 20; total += i, i += 2); Which of the following is not a type of repetition statement in Java? - Answer loop statement Which of the following statements about a do...while repetition statement is true? - Answer The body of a do...while loop is always executed at least once. Which of the following statements about the break statement is false? - Answer The break statement, when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. Which of the following statements about the continue statement is true? - Answer A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement. Which statement prints the floating-point value 123.456 right justified with a field width of 10? - Answer Sf("%10.3f", 123.456); boolean values can be displayed as the words true and false with the ________ format specifier. - Answer %b The preferred way to traverse a two-dimensional array is to use ________. - Answer two nested for statements Which of the following statements is false? - Answer Variables of type boolean are initialized to true. Invalid possibilities for array indices include ________. - Answer negative integers Which of the following initializer lists would correctly set the elements of array n? - Answer int[] n = {1, 2, 3, 4, 5}; When you pass an array or an individual array element of a reference type to a method, the called method receives ________. When you pass an individual element of a primitive type, the called method receives ________. - Answer a copy of the element's reference, a copy of the element's value Which of the following statements about creating arrays and initializing their elements is false? - Answer The elements of an array of integers have a value of null before they are initialized. Consider the code segment below. Which of the following statements is false? int[] g; g = new int[23]; - Answer The value of g[3] is -1. What do the following statements do? double[] array; array = new double[14]; - Answer Create a double array containing 14 elements. Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int, long, float and double. All other types are ________ types. - Answer reference Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements? - Answer int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}}; Which expression adds 1 to the element of array arrayName at index i? - Answer ++arrayName[i] An argument type followed by a(n) ________ in a method's parameter list indicates that the method receives a variable number of arguments of that particular type. - Answer ellipsis(...) When an argument is passed by reference, ________. - Answer the called method can access the argument's value in the caller directly and modify that data Which of the following tasks cannot be performed using an enhanced for loop? - Answer Incrementing the value stored in each element of the array. Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items? - Answer int[][] items; items = new int[?][?]; items[0] = new int[1]; items[1] = new int[4]; items[2] = new int[2]; Which statement below initializes array items to contain 3 rows and 2 columns? - Answer int[][] items = {{2, 4}, {6, 8}, {10, 12}}; Arrays are ________. - Answer fixed-length entities Which statement correctly passes the array items to method takeArray? Array items contains 10 elements. - Answer takeArray(items) Which method call converts the value in variable stringVariable to an integer? - Answer IInt(stringVariable) Which of the following statements about arrays are true? A. An array is a group of variables containing values that all have the same type. B. Elements are located by index. C. The length of an array c is determined by the expression h();. D. The zeroth element of array c is specified by c[0]. - Answer A, B, D
Written for
- Institution
- CSC200
- Course
- CSC200
Document information
- Uploaded on
- September 8, 2023
- Number of pages
- 13
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers