CS A170 Java 1 final exam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

37. when writing the documentation comments for a method, every parameter should have a ______ tag

@param

12. what is the output of the following code snippet? int [ ] values = { 10, 20, 30, 7 }; int [ ] number = values; numbers[2] = 24; values[3] = numbers [0] + 6; System.out.println(numbers[2] + " " + numbers[3] + " " + values[2] + ' ' + values[3]); a. 24 7 30 16 b. 24 0 30 16 c. 24 16 24 16 d. 24 0 30 6

C. 24 16 24 16

what happens when you pass two values that are not equal to tge Assert.assertEquals method?

JUnit reports a failure for the test case

immutable classes

PrintStream

13. given int one ; double two; boolean four; which of the following assignment statements are valid? (i) one = 7 + 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3); a. (i) and (iii) are valid b. only (i) is valid c. (ii) and (iii) are valid d. (i) and (ii) are valid

a. (i) and (iii) are valid

33. to use a local variable in a different method, you pass the variable as ________ a String an actual parameter a form parameter an int

an actual parameter

3. identify the correct statement for defining an integer array name 'numarray' of ten elements. a. int numarray[10]; b. int[10] numarray; c. int[ ] numarray = new int[10]; d. int[ ] numarray = new int[9];

c. int[ ] numarray = new int[10];

consider a class Circle that represents a circle in the plane. which of the following methods would make the public interface non-cohesive? - double getRadius() - double getPerimeter() - double getArea() - double getArea(Rectangle r)

double getArea(Rectangle r)

34. what does <= mean? less than or equal to less than greater than greater than or equal to

less than or equal to

30. statements in which 'if' structure is contained inside another 'if' structure commonly are called _______ if statements logical blocked nested inside

nested

36. when retrieving characters from a String,(str), the position of the last character is: str.length() str.length() - 1 0 1

str.length() - 1

11. assume the following variable has been declared and given a value as shown: int[ ] numbers = {9, 17, -4, 21 }; A. 4 B. 3 C. 21 D. 9

A. 4

10. consider the following code snippet. which statement should be used to fill in the empty line so that the output will be [32, 54, 67.5, 29, 35]? public static void main(String[] args) { doble data[ ] = {32, 54, 67.5, 35}; System.out.println(str); } A. String str = str + ", " + data[i]; B. String str = Arrays.toString(data); C. String str = data.toString()'; D. String str = Arrays.format(data);

B. String str = Arrays.toString(data);

9. consider the the following cope snippet: String[ ] data = { "abc", "def", "ghi", "jkl" }; String [ ] data2; in Java 6 and later, which statement copies the 'data' array to the 'data2' array? A. data2 = Arrays.copyOf(data, data2.size()); B. data2 = Arrays.copyOf(data, data2.length); C. data2 = Arrays.copyOf(data, data2.length); D. data2 = Arrays.copyOf(data);

B. data2 = Arrays.copyOf(data, data2.length);

15. which of the following code snippet will generate a random number between 0 and 79? A. int val = (int) (Math.random() & 80); B. int val = (int) (Math.random() * 80 - 1); C. int val = (int) (Math.random() % 79); D. int val = (int) (Math.random() * 80);

D. int val = (int) (Math.random() * 80);

5. what is displayed after executing the given code snippet? int[ ] mymarks = new int [ 10 ]; int total = 0; Scanner in = new Scanner(System.in); for (int cnt = 1; cnt <= 10; cnt++) { System.out.print("Enter the marks: "); mymarks[ cnt ] = in.nextInt( ); total = total + mymarks[ cnt ]; } System.out,.println(total); A. the code snippet displays the total marks of all ten subjects. B. the code snippet displays zero. C. the for loop causes a run-time time error on the first iteration. D. the code snippet causes a bounds error.

D. the code snippet causes a bounds error.

When you run the BankAccountTester program of this section, how many objects of class BankAccount are constructed? How many objects of type BankAccountTester? No objects of either class are constructed. One object of class BankAccountTester, no object of class BankAccount One object of class BankAccount, no object of class BankAccountTester One BankAccount object, no BankAccountTester object. The purpose of the BankAccountTester class is merely to hold the main method. One object of each class.

One BankAccount object, no BankAccountTester object. The purpose of the BankAccountTester class is merely to hold the main method.

2. consider the following line of code: int[ ] somearray = new int[30]; which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray? a. System.out.println(somearray[27]); b. System.out.println(somearray(28)); c. System.out.println(somearray[28]); d. System.out.println(somearray(27));

a. System.out.println(somearray[27]);

1. which one of the following statements is true about using arrays with methods? a. arrays can be methods of arguments, and return values, just like any other value. b. a method may accept an argument that is an array, but what the heck is an array anyway. c. method can only accept arguments that are elements of an array, but not the whole array. d. a method may accept an argument that is an array, but it cannot return a result that is an array. f. if a method is defined to have an array as a method argument, it must also define the size of the array as another method argument.

a. arrays can be methods of arguments, and return values, just like any other value.

32. to retrieve a single character from a String, use the _______ function, along with the position of the character you wish to retrieve. substring() char() charAt() nextChar()

charAt()

40. you can use the _______ , which is written as ||, if you want some action to occur when at least one of two conditions is true. switch statement range check logical AND operator logical OR operator

logical OR operator

which method of the scanner class is used to read an integer?

next.Int()

35. what is the output of the following java code? int x = 6; if (x > 10) System.out.print("One "); System.out.print("Two "); Two One One Two None of these

none of these

library classes such as ArrayList or String

not possible to add methods

suppose JUnit reported an error, and you fixed it. What should you do next?

run the test class again with JUnit

38. out of while, for, switch, which is not a repetition structure in Java

switch

if you do not include a package statement at the top of your class source file, its classes will be placed in which package?

the default package, which has no name

as a rule of thumb, a mutator method should not return a value. which of the following methods bends this rule? use the API documentation to find out.

the remove method of the ArrayList class

29. dividing a number by 0.0 results in:

the special NaN or Not a Number value

thisIS. all CAPS means it constant in java

this is now how you use camelCase

31. suppose x is 5 and y is 7. what is the value of the following expressions? (x != 7) && (x <= y) true false this is an invalid expression in java none of the above

true


Set pelajaran terkait

Law of Commercial Transactions Midterm

View Set

Econ 2: Chapter 16 Inflation, Disinflation, Deinflation

View Set

Chapter 3: Medication Administration and the Nursing Process of Drug Therapy

View Set

math ra questions for r.1-r.7 test

View Set