Comp Sci Final Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The output of the following program is _____. public class Test { public static void main(String[] args) { int [] a = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; for (int i = a.length-1; i >= 0; i--) System.out.print(a[i] + " "); } } a. 2 4 6 8 10 12 14 16 18 20 c. 20 19 18 17 16 15 14 13 12 11 10 b. 20 18 16 14 12 10 8 6 4 2 d. 2 3 4 5 6 7 8 9 10 11 12 13 14 15

B

The parameter(s) of the following method is(are) _____. public int method1(int x, int y) { int z; ... return z; } a. x, y, and z b. x and y c. z d. x and z

B

To find the square root of 9.0, you would call the following statement(s) _____. a.Math m = new Math(); m.sqrt(9.0); c. Math m = new Math(9.0); m.sqrt(); b.Math.sqrt(9.0); d.Math.squareRoot(9.0);

B

What is the output of the following program? public class Test { public static void main(String[] args) { String myString = "A class about strings"; String myString2 = myString.substring(0, 13) + " main"; System.out.println(myString2); } } a. A class about strings c. A class main b. A class about main d. A class aboutmain

B

Text that appears between an opening /* and a closing */ is a(n) ____. a. end-of-line comment c. debugging statement b. multiline comment d. expression

B

What is the value of answers.length? boolean[] answers = { true, false, true, true, false }; a. 2 b. 5 c. 4 d. 6

B

Which method will allow you to test strings without regard to capitalization? a. equals() c. equals(true) b. equalsIgnoreCase() d. equals(false)

B

____ is when the same name is used for two different methods. a. Infinite loop b. Overloading c. Iteration d. Sentinel

B

The following method _____. public class Student { private int id; ... } a.can not be accessed anywhere b.can only be accessed in the class it is declared c.can only be accessed from all classes in the same folder d.can be accessed from anywhere

B

The output of the following program is _____. public class Test { public static void main(String [] args) { int n = 5; for (int i=0; i < 10; i++) n += (i%3); System.out.println("n = " + n); } } a. n = 50 b. n = 14 c. n = 10 d. n = 100

B

57. What is the output of the following program? public class Test { public static void main(String [] args) { int n = 5; for (int i=0; i < 10; i++) n += i; System.out.println("n = " + n); } } a. n = 15 b. n = 14 c. n = 50 d. n = 10

C

The output of the following program is _____. public class Test { public static void main(String[] args) { String s1 = "Programs"; String s2 = "programs"; if (s1.equalsIgnoreCase(s2)) System.out.println("True"); else System.out.println("False"); } } a. programs b. True c. False d. Programs

B

59. The output of the following program is: _____. public class Test { public static void main(String [] args) { double [] a = {1.2, 2.4, 5.6, 7.3, 10.12, 45.87}; int index = -1; int i = 0; while(index==-1 && i < a.length; i++) { if (a[i] == 10.12) index = i; else i++; } System.out.println(i); } } a. -1 b. 3 c. 4 d. 5

C

What is the output of the following program? public class Test { public static void main(String [] args) { int x = 100; int y = 5; int z = -2; z *= (x % y) + (x / y); System.out.println("z = " + z); } } a. z = -10 b. z = -500 c. z = -25 d. z = -40

D

What is the value of x after the following statements execute? int x = 200; int y = 50; x -= y; a. 200 b. 50 c. 250 d. 150

D

Which of the following is an example of an IDE? a. Java b. Word c. jGrasp d. Excel

D

Which of the following is true about using a text file for input? a.The data set can be much larger. b.Data can be input faster and with less chance of error. c.Data can be used repeatedly with the same program or with different programs. d.All of the above are true.

D

The physical devices you see on your desktop are called ____. a. software b. hardware c. peripherals d. PDAs

..B

46. The first salesFigure in the following array declaration is _____. double [] salesFigure = new double[20]; a. salesFigure[0] c. salesFigure[2] b. salesFigure[1] d. salesFigure[19]

A

54. What do we call a loop that never ends? a. infinite b. definite c. counted d. limitless

A

6. The output of the following program is _____. public class Test { public static void main(String[] args) { String s1 = "A simple program"; boolean b = s1.startsWith("A simple program"); System.out.println("b = " + b); } } a. b = true b. b = false c. b = -1 d. b = 1

A

64. Which one of the following is the correct declaration for a String array? a. String anArrayOfStrings; c. String[] anArrayOfStrings; b. anArrayOfStrings String[]; d. string[] anArrayOfStrings;

A

Caroline uses the ____ character to include quotation marks in the welcome message. a. escape b. output c. concatenation d. forward slash

A

The expression (3 + 5) + 2* 2 + 4 will yield ____ as the answer. a. 16 b. 20 c. 24 d. 60

A

public class Test { public static void main(String [] args) { int i = 2; increment(i); } public static void increment(int x) { int i = 10; i++; System.out.println("The value of i is: " + i); } } a. The value of i is: 11 c. The value of i is: 0 b. The value of i is: 2 d. The value of i is: 3

A

public class Test { public static void main(String[] args) { String name = "Jack Smith"; int i = name.indexOf(' '); System.out.println("i = " + i); } } a. i = 4 b. i = 3 c. i = 5 d. i = -1

A

14. Math.ceil(4.1) yields _____. a. 4.0 b. 5.0 c. 4.10 d. 4.5

B

29. The identifier in the following statement is _____. double salary = 30000; a. double b. salary c. = d. 30000

B

58. The output of the following program is _____. public class Test { public static void main(String [] args) { int[] a = new int[7]; for(int i=0; i < 5; i++) { a[i] = i % 2; } printArray(a); } public static void printArray(int [] a) { for(int i=0; i < a.length; i++) { System.out.print(a[i] + " "); } } } a. 0 1 0 1 0 1 1 c. 1 0 1 0 0 0 0 b. 0 1 0 1 0 0 0 d. 0 1 0 1 0 1 1

B

public class Test { public static void main(String [] args) { int[] a = {2, 4, 6, 8, 10, 12, 14}; for(int i = 0; i < a.length; i++) { if (i > 5) a[i] *= 2; } printArray(a); } public static void printArray(int [] a) { for(int i=0; i < a.length; i++) { System.out.print(a[i] + " "); } } } a. 2 4 6 8 10 24 28 c. 2 4 12 16 20 24 28 b. 2 4 6 8 10 12 28 d.2 4 6 8 10 12 14

B

All of the following are examples of software, EXCEPT ____. a. Google Chrome b. Angry Birds c. CPU d. JGrasp

C

Data can be output to a text file using the class ____. a. Scanner b. WriteData c. PrintWriter d. TextFile

C

If A = 5, B = 0, and C = (A > B) || (A > 15), then the value of C is _____. a. 5 b. 15 c. true d. false

C

The result of the following expression is _____. 6 + 2 * 3 - 4 a. -8 b. 4 c. 8 d. 20

C

The value of b after the following statements are executed is _____. int b = 17; int c = 10; b /= c; a. 1.7 b. 18.7 c. 1 d. 0

C

The value of x after the following statements are executed is _____. x = 10; x *= 10; a. 10 b. 11 c. 100 d. 1000

C

What is the value of result? String s = "Programming"; boolean result = s.startsWith("Program"); a. 0 b. 1 c. true d. false

C

Which of the following contains the classes your need to create a File object? a. java.file; b. java.import; c. java.io; d. java.util

C

Which of the following is an example of an IDE? a. Java b. Word c. jGrasp d. Excel

C

25. What is the output of the following program? public class Test { public static void main(String[] args) { String [] a = {"This", "is", "a", "test"}; for (int i = 0; i < a.length; i++) { if (a[i].length() > 2) System.out.print(a[i] + " "); } } } a. This is a b. This is c. this test d. This test

D

A typical loop has four component parts, including all of the following EXCEPT ___ statements. a. initializing b. body c. update d. verification

D

12. Math.round(- 4.1) yields _____. a. -4 b. -5 c. -3 d. -6

A

18. What is the output of the following program? public class Test { public static void main(String[] args) { String s1 = "Testing"; String s2 = "testing"; String s3 = s1.toLowerCase(); if (s2.equals(s3)) System.out.println("true"); else System.out.println("false"); } } a. true b. false c. Testing d. testing

A

23. Each element of myArray has a value of _____. int [] myArray = new int[10]; a. 0 b. null c. -1 d. 1

A

The value of x in the following statement is _____. int x = 9 % 4; a. 1 b. 2 c. 3 d. 4

A

A ____ error occurs when the computer is instructed to divide by 0. a. Syntax b. Run-time c. Logic d. Semantic

B

A person's first name is most likely stored in a(n) _____. a. char b. String c. int d. long

B

Array and String indexing starts at _____. a. -1 b. 0 c. 1 d. a value specified by the user

B

If getAccountDetails() is a class method, then which keyword modifier would be used with this method? a. public b. static c. void d. private

B

3. In the following method, the return type is _____. public void setBalance(double value) { balance = value; } a. void b. public c. value d. double

A

36. An example of a constant in the Math class is _____. a. Math.PI b. Math.COS c. Math.ABS d. Math.TAN

A

66. 1 is the result of which of the following? a. 13 % 4 b. 15 % 4 c. 8 % 4 d. 14*6

A

7.Which of the following is not a primitive type? a. String b. char c. double d. boolean

A

88. In a method, the return type should be ____ when the method returns no value. a. void b. null c. 0 d. { }

A

If Ari wants to change the order in which numbers are calculated, he should add ____ to them. a. parentheses b. literals c. slashes d. mixed-modes

A

Inside the Account class, Account() is a(n) _____. public class Account { public Account() { balance = 0.0; } ... } a. constructor b. initializer c. instance variable d. accessor

A

The output of the following program is _____. public class Test { public static void main(String[] args) { String s1 = "This is string 1"; char c = s1.charAt(15); System.out.println(c); } } a. 1 b. g c. n d. the space character

A

The process of creating a new object is called ____. a. instantiation b. modification c. encapsulation d. identification

A

What is the output of the following program? public class Test { public static void main(String [] args) { int [] a = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int value = 9; boolean foundIt = false; for(int i=0; i < a.length; i++) { if (a[i] == value) { System.out.println(i); foundIt = true; } } if (!foundIt) System.out.println("value not found"); } } a. 8 b. value not found c. -1 d. 9

A

What is the output of the following program? public class Test { public static void main(String[] args) { String s1 = "The String is: AAAA BBB SsSsSs"; String s2 = s1.replace('s', 'S'); System.out.println(s2); } } a.The String iS: AAAA BBB SSSSSS c.The String is: AAAA BBB ssssss b.The String iS: AAAA BBB ssssss d.The String is: AAAA BBB SSSSSS

A

What is the output of the following program? public class Test { public static void main(String[] args) { int [] a = new int[10]; for (int i = 0; i < a.length; i++) a[i] = i / 2; for (int i=0; i < a.length; i++) System.out.print(a[i] + " "); } } a. 0 0 1 1 2 2 3 3 4 4 c. 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 b. 0 1 2 3 4 5 d. 0 1 2 3 4 5 6 7 8 9 10

A

a.for (int j = array.length; j>=0; j--) System.out.println(array[j]); c.for (int j = array.length; j>=0; j++) System.out.println(array[j]); b.for (int j =0; j<array.length; j++) System.out.println(array[j]); d.for (int j = array.length; j<0; j--) System.out.println(array[j]);

A

public class Test { public static void main(String [] args) { double[] a = new double[10]; for(int i=0; i < a.length; i++) { a[i] = i * 4; } printArray(a); } public static void printArray(double [] a) { for(int i=0; i < a.length; i++) { System.out.print(a[i] + " "); } } } a. 0.0 4.0 8.0 12.0 16.0 20.0 24.0 28.0 32.0 36.0 b. 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 18.0 c. 4.0 8.0 12.0 16.0 20.0 24.0 28.0 32.0 36.0 d. 0.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0

A

8. What would the following println statement print? double [] myArray = new double[10]; System.out.println(myArray.length); a. 9 b. 10 c. 11 d. 10.00

B

9. Evaluate the following Math.ceil(7.1)+Math.floor(8.7)? a. 15 b. 16 c. 17 d. 18

B

public class Test { public static void main(String [] args) { method1(50, 30); } public static void method1(int x, String y) { System.out.println("method1(int, String) was called"); } public static void method1(double x, int y) { System.out.println("method1(double, int) was called"); } } a. method1(int, String) was called b. method1(double, int) was called c. Compiler error, both good matches. d. method1(50, 30) was called

B

10. In the following declaration, myAccount is a(n) _____. Account myAccount = new Account(2000); a. instance variable b. declaration c. object d. class

C

22. The output of the following program is _____. public class Test { public static void main(String[] args) { String location = "downtown"; int j = location.indexOf('m'); System.out.println("j = " + j); } } a. j = 4 b. j = 0 c. j = -1 d. j = 8

C

33. What is the correct declaration for a constant named COUNT? a. static int COUNT; c. static final int COUNT = 100; b. static int COUNT = 100; d. int COUNT = 100;

C

39. What is the index of 300? int [] a = {50, 75, 100, 150, 200, 300, 450, 510, 700}; a. 3 b. 4 c. 5 d. 6

C

If you have a variable named salary in the Employee class, you would most likely _____. a.make salary public so everyone can access it b.make salary private so no one can access it, and do not provide any method to get and set the salary c.make salary private and create two public methods: one to get salary and one to set salary d.make salary static

C

Parameters listed in a method's header are called ____ parameters. a. class b. actual c. formal d. argument

C

The three steps to writing and running a program, in order, are ____. a. enter, edit, compile c. edit, compile, execute b. edit, execute, compile d. enter, interpret, compile

C

The value of x after the following statements execute is _____. int x = 15; int y = 10; x += y; a. 10 b. 15 c. 25 d. 150

C

What is the output of the following program? public class Test { public static void main(String [] args) { String [] a = {"Java", "Programming"}; for(int i = 0; i < a.length; i++) { char ch = a[i].charAt(0); if (Character.isUpperCase(ch)) { a[i] = a[i].toUpperCase(); } } for (int j = 0; j < a.length; j++) System.out.print(a[j] + " "); } } a. jAVA pROGRAMMING c. JAVA PROGRAMMING b. java programming d. Java Programming

C

Which of the following is NOT true about variables? a.Their values can change during execution. b.Before using a variable for the first time, the program must declare its type. c.The type of data a variable contains can be changed. d.All of the above are true.

C

int X = 10; if (X >= 10) { System.out.print("ABC"); System.out.println("XYZ"); } a. ABC b. XYZ c. ABCXYZ d. ABC XYZ

C

What is the output of the following program? public class Test { public static void main(String [] args) { int x = 0; int i, j; for (i = 0; i < 10; i++) for (j = 10; j > 4; j--); x += i; System.out.println("x = " + x); } } a. x = 100 b. x = 60 c. x = 600 d. x = 10

D

1. What is the output of the following program? public class Test { public static void main(String[] args) { String string1 = "JAVA"; String string2 = "Java"; if (string1.equals(string2)) System.out.println("string1 equals string2"); else System.out.println("string1 does not equal string2"); } } a. true c. JAVA b. string1 equals string2 d. string1 does not equal string2

D

90. In the sentence "If the sun is shining AND it is 8 a.m. then let's go for a walk; else let's stay home," which of the following is true? a.If both operands are true, the condition as a whole is true. c.If either operand is false, the condition is false. b.If both operands are false, the condition is false. d.All of the above are true.

D

An object has ____, as defined by the methods of its class. a. state b. identity c. scope d. behavior

D

How many constructors can we have in one class? a. 1 b. 2 c. 3 d. as many as we want

D

Math.pow(2.0, 3.0) yields _____. a. 2.0 b. 4.0 c. 6.0 d. 8.0

D

Sending a message to a variable before the corresponding object has been instantiated causes a(n) ____ exception. a. no such method b. syntax c. desk checking d. null pointer

D

String s = "Application"; char c = s.charAt(5); a. i b. l c. a d. c

D

The ____ character is used to print out a backslash (\) or quote("). a. * b. = c. ( d. \

D

The following statement is equivalent to _____. total += amount; a. amount = amount + total; c. total = amount + 1; b. total += total + amount; d. total = total + amount;

D

To use a method successfully, you must know ____. a.what type of value it returns b.its name c.the number and type of the parameters it expects d.all of the above

D

public class Test { private int myInt; public Test() { myInt = 0; } public Test(int temp) { myInt = temp; } public int getMyInt() { return myInt; } ******************NEW FILE************************ public class TestTester{ public static void main(String [] args) { Test t = new Test(123456); System.out.println("The value of myInt is: " + getMyInt()); } } a.The value of myInt is: temp b.The value of myInt is: myInt c.The value of myInt is: 0 d.The value of myInt is: 123456

D

public double doSomething(int A, int B, double C) { int X = A + B; double Z = X*C; return ...; } a. X b. C c. B d. Z

D


संबंधित स्टडी सेट्स

Ch12: Reporting Cash Flows ACCT 211

View Set

ATI Pharmacology Made Easy 4.0 ~ The Neurological System (Part 2)

View Set

数学(中学三年生)平方根

View Set

Prep-U Chapter 13: Fluid and Electrolytes: Balance and Disturbance

View Set

Chapter 48- Drugs for Skin Disorders

View Set

Ch 13: Cultural Diversity and Community Health Nursing

View Set