AP Comp Sci final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/103

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

104 Terms

1
New cards

In Java, there are only 8 primitive data types.

True

2
New cards

The int data type is capable of storing floating-point numbers.

False

3
New cards

The int variable uses the sane amount of space as a double variable.

False

4
New cards

The equals sign (=) is known as the assignment operator.

True

5
New cards

The compiler will ignore indentation that appears in the middle of a word.

False

6
New cards

Java, include statements are used to gain access to libraries outside of default Java Library.

False

7
New cards

Given the following class header

public class MoonWeight {...}

for the following program MoonWeight to compile, it must be saved in which of the following files?

MoonWeight.java

8
New cards

Which of the following statements is a valid variable declaration statement?

int x;

9
New cards

Which of the following operators has the highest precedence?

/ and *

10
New cards

In Java, the expression (3/4) + 7.0 evaluates to

7.0

11
New cards

In Java, the expression (12/3.0) * (1/2) evaluates to

0.0

12
New cards

Which of the following number literals is invalid in Java?

2,700

13
New cards

In Java, every variable data type is either a primitive data type or a(n)

Object

14
New cards

Which of the following is not a primitive data type?

String

15
New cards

Given the following Scanner object:

Scanner input = new Scanner (System.in);

Which of the following methods can be used to obtain a string from the user?

input.nextLine();

16
New cards

Java sets aside certain key words that have a special meaning or action known as

Reserved words

17
New cards

Which of the following is an invalid user-defined symbol?

-void

-lucky7

-PILLOWS

-None of the above

-void

18
New cards

Which of the following is an invalid user-defined symbol?

-First_name

-1time <--- Answer

-$income

-None of the above

-1time

19
New cards

Camel casing is a naming convention in which

Multiple words are combined and uppercase letters are used to distinguish words.

20
New cards

Which of the following symbols is used to enclose a string literal?

None of the above

21
New cards

A multi-line comment begins with the symbol or /*.

Which of the following symbols mark the end of a multi-line comment?

*/

22
New cards

What is printed as a result of executing the following code segment?

double x = 2;

SOP("x + x");

x + x

23
New cards

What is printed as a result of executing the following code segment?

int x = 3;

SOP("Total: " + x + 4.0);

Total: 7.0

24
New cards

πr^2

Which of the following Java expressions can be used to evaluate the above arithmetic expression?

Math.pow(r, 2) * Math.PI

25
New cards

|x| + √x

Which of the following Java expressions can be used to evaluate the above arithmetic expression?

None of the above

26
New cards

A syntax error is also known as

compile-time error

27
New cards

One (1) bit is comprised of eight (i) bytes

False

28
New cards

ENIAC, one of the world's first electronic computers, used transisters in order to store and process data

True

29
New cards

Lossless compression should be used when loss of information could pose a problem. Such as with text documents + spreadsheets

True

30
New cards

The jpeg image format uses lossy compression to reduce the file size of images

True

31
New cards

Which of the following can be represented by a single binary digit?

B. The remainder when dividing a whole # by 2

C. The value of a Boolean value

32
New cards

A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5+3, the result is 0. Which of the following is the best explanation for the result.

An overflow error occurred

33
New cards

What ASCII character is represented by the binary (base 2) number 1001010?

J

34
New cards

Digital images are often represented by red, green, & blue values of each individual pixel in the image. A photographer is manipulating a digital image and overwriting the original image. Which of the following describes lossless transformation of the digital image?

C. Creating the negative of an image by creating a new RGB triplet for each pixel in which each value is calculated by subtracting the original value from 255. The negative of an image is reversed from the original; light areas appear dark and colors are reversed.

35
New cards

______ invented the e-machine, helped break the Enigma code during WW2 and wrote a paper that is considered the foundation of Computer Science

Alan Turing

36
New cards

______ is the observation that, over the history of computing hardware, the # of transistors in a dense integrated circuit has doubled approx every 2 years.

Moore's Law

37
New cards

(Pseudocode) Which of the following Boolean exprssions are equivalent to the epxression num >= 15 (select 2)

B. (num > 15) or (num = 15)

C. (NOT (num < 15)

38
New cards

Which of the following digital storage units has the largest capacity?

Terabyte

39
New cards

(Pseudocode) In the program below, the initial value of x is 5 and the initial value of y is 10

C. November

40
New cards

Which of the following is not a logical operator?

!=

41
New cards

Which of the following changes will NOT affect the results when the code segment is executed?

1: IF (a=0)

2: {

3: b <- a + 10

4: }

5: else

6: {

7: b <- a + 20

8: }

Changing line 3 <- 10

42
New cards

What is printed to the user if he/she enters a time of 8?

int ware = 8;

int time = input.nextInt();

if (ware < time)

{

System.out.println("Get out of bed! You're late!");

}

System.out.println("Have a good day!");

B. Have a good day!

43
New cards

What is printed to the user?

boolean snowDay = true;

if (!snowDay)

System.out.println("Stay Inside!");

System.out.println("The weather outside is frightful!");

B. The weather outside is frightful!

44
New cards

What is printed to the user if he/she enters a yr of 1999?

int year = input.nextInt();

if (year <= 1999)

{

System.out.println("Let's drive!");

}

else

{

System.out.println("Wait a big longer...");

}

System.out.println("Age check complete.");

A. Let's Drive

Age Check Complete

45
New cards

Which of the following Java expression is equivalent to the algebraic expression 3 < x <= 6

A. x <= 6 && X > 3

46
New cards

What is printed if the user enters 60?

int speed = intput.nextInt(); // get speed from user

if (speed <= 60) {

System.out.println("Safe travels!");

} else if (speed < 65) {

System.out.println("Slow down! Be careful!");

} else if (speed > 65) {

System.out.println("Caught speeding!")

}

Safe travels!

47
New cards

What is printed if the user enters 64?

int speed = intput.nextInt(); // get speed from user

if (speed <= 60) {

System.out.println("Safe travels!");

} else if (speed < 65) {

System.out.println("Slow down! Be careful!");

} else if (speed > 65) {

System.out.println("Caught speeding!")

}

Slow down! Be careful!

48
New cards

What is printed if the user enters 65?

int speed = intput.nextInt(); // get speed from user

if (speed <= 60) {

System.out.println("Safe travels!");

} else if (speed < 65) {

System.out.println("Slow down! Be careful!");

} else if (speed > 65) {

System.out.println("Caught speeding!")

}

None of the above (nothing is printed)

49
New cards

Given:

int x = 7;

Which of the following expression will trigger short-circuit evaluation?

A: x != 7 && x < 10

50
New cards

The expression !(x < 1 && x >= 10) is equivalent to which of the following expression?

x >= 1 || x < 10

51
New cards

Given the following program:

public class Vote

{

public static void main(String[] args)

{

int age = 20;

if (age >= 18)

{

System.out.println("Can vote.");

} // A

else

{

System.out.println("Can't vote");

} // B

} // C

} // D

The scope of the variable age ends with which brace?

A: C

52
New cards

(Pseudocode) The code fragment below is intended to display "add" if the positive num is add.

IF ()

{

DISPLAY("add")

}

Which of the following can be used to replace so that the code fragment will work as intended?

A: (num MOD 2) = 1

53
New cards

String is one of the 8 primitive data types

False

54
New cards

The process of "adding" Strings together is known as concatenation

True

55
New cards

The last index in a non-empty String is always one less than its length

True

56
New cards

The String IDE documents all of the information needed to work with String objects including a complete list of methods

False (It's API)

57
New cards

What is printed?

String lj = "Leeroy Jenkins!";

boolean result = lj.equals("leeroy jenkins!");

System.out.println(result);

False

58
New cards

Which of the following set of symbols is used to construct a String literal?

" "

59
New cards

Given: String thg = "I volunteer as tribute";

Which of the following expressions makes a comparison between two characters?

thg.charAt(2) == 'v'

60
New cards

Which of the following String methods is overloaded?

substring and indexOf

61
New cards

Consider the following method signature:

String :: my Method(int) :: boolean

What data type does the above method return?

boolean

62
New cards

Given: String movie = "The Imitation Game";

Which of the following method calls would cause a StringIndexOutOfBoundsException?

none

63
New cards

What is printed:

String nums = "4321";

if (nums.length() % 2 == 0)

System.out.println(nums.charAt(1));

else

System.out.println(nums.charAt(2));

3

64
New cards

What is printed:

String hulk = "Hulk Smash";

String output = "";

for (int i=0; i

uk Sah

65
New cards

What is printed:

String sport = "football";

String output = "";

for (int i=0; i

fotbal

66
New cards

What is printed:

String horrible = "What a crazy random happenstance";

char c = horrible.charAt(2)

for (int i=horrible.length(); i >=0; i--)

if (horrible.charAt(i) == c)

System.out.print("cray");

none (IndexOutOfBoundsException)

67
New cards

What is printed:

Srring joker = "Why so serious?";

String output = "";

for (int i=joker.length()-1; i<=0; i--)

if (joker.charAt(i) != 'i')

output += joker.charAt(i);

System.out.println(output);

?suores os yhW

68
New cards

Given:

String fma = "Edward Elric";

Which of the following method calls returns "Elric"?

fma.substring(7); and fma.substring(7,fma.length());

69
New cards

What is printed:

String lulu = "That tasted purple!";

String temp = lulu.substring(1, lulu.length()-1);

String out.println(temp);

hat tasted purple!

70
New cards

What is printed:

String str = "Thrones";

System.out.println(str.substring(str.length / 2));

ones

71
New cards

What is printed:

String str = "Surprised Pikachu";

System.out.println(str.substring(3).indexOf("P");

7

72
New cards

What is printed:

String str = "yoyo";

String output = "";

for (int i=0; i

yoyooyoyoo

73
New cards

What is printed:

String greeting = "Hello, World!";

System.out.println(greeting.indexOf("o"));

4

74
New cards

Given:

String str = "Fire and Blood!";

System.out.println();

Which could replace missing code and cause code segment to print -1?

str.indexOf("b");

75
New cards

What is printed:

String str = "tall door bell";

String output = "";

for (int i=0; i

tal dorbe

76
New cards

What is printed:

String winter = "Happy Holla Days!";

int i = winter.indexOf("a");

while (i >= 0)

{

System.out.print(i);

winter = winter.substring(i+1);

i = winter.indexOf("a");

}

182

77
New cards

The following code should print "that wasnt very cash money of you" for every character that is not a '$'. Which of the following should replace missing code so that the code works as intended?

String str = "$Godzilla$";

for (int i=0; i

System.out.println("That wasnt very cash money of you");

str.charAt(i) != '$'

78
New cards

The following code segment should print every other character from str for example, if str <-- "xoxoxo", the code segment would print "xxx". Which of the following should replace so that the code segment works as intended?

String str = "They did surgery on a grape."";

String rtn = "";

for(int i = 0; i < str.length(); i++)

if ()

rtn += str.charAt(i);

SOP(rtn);

i % 2 == 0

79
New cards

x-- is functionally equivalent to x = x-x

False

80
New cards

The body of a while-loop will always execute at least once time

False

81
New cards

The second statement in the header of a for-loop is the loop's condition

True

82
New cards

The braces that indicate the body of a loop can be ommitted if the loop contains only 1 statement

True

83
New cards

An IOException is a compile-time (syntax) error

False

84
New cards

The expression i++ is equivalent to which of the following statement?

1) i = i + 1

2) i = 1 + 1

3) i += 1

1 and 3 only

85
New cards

Which of the following is not an assignment operator?

=-

86
New cards

Which is printed by the following code fragment?

int x = 3;

x *= 3;

x /= 4;

System.out.println(x);

2

87
New cards

A single execution of the loop's body is known as which of the following?

Iteration

88
New cards

(Psudocode) Consider the following code segment:

j <- 1

Repeat until ()

{

j < j *2

}

j = 6

89
New cards

What is printed by the following code segment?

int count = 1;

while (count < 7)

{

if (count % 2 != 0)

System.out.print(count);

count++;

}

135

90
New cards

What is printed by the following code segment?

int x = 15;

int count = 1;

while (count <= x)

{

if (x % count == 0)

{

System.out.print(count);

x -= count;

}

count += 1;

}

1239

91
New cards

What is printed by this following code segment?

int c=0;

while (c < 6)

{

System.out.print(c + "+" + c);

c++;

}

0+01+12+23+34+45+5

92
New cards

Consider the following code fragment:

int i=12;

while (i>0)

{

if (i % 2 != 0)

{

i = i - 3;

}

i--;

}

System.out.println(i);

-1

93
New cards

Programs I and II below are each intended to calculate the sum of the integers from 1 to n. Assume that n is a positive integer (e.g. 1,2,3...)

Program I:

i <- 1

result <- 0

REPEAT n TIMES

{

result <- result + i

i <- i + 1

}

DISPLAY(result)

Program II:

i <- n

result <- 0

REPEAT n TIMES

{

result <- result + i

i <- i - 1

}

DISPLAY(result)

Which of the following best describes the behavior of the 2 programs?

Both program I and program II displays the correct sum

94
New cards

Consider the following code fragment:

int sum = 0;

int outer = 1;

while (outer <= 2)

{

int inner = 1;

while (inner <= outer)

{

sum += inner;

inner++;

}

outer++;

}

System.out.println(sum);

What is printed as a result of executing the coding segment?

4

95
New cards

What is printed by the following code segment?

for (int i=0; i <=8; i++)

{

if (i % 2 = 0)

System.out.println(i);

}

2

4

6

8

96
New cards

Consider the following code fragment:

boolean q = false;

int x = 10;

for (int i=0; i

x -= i;

else

System.out.print(q);

System.out.print(x)

if (x % 3 == 0)

i++;

}

10961

97
New cards

Consider the following code segment:

i <- 1

counter <- 1

REPEAT UNTIL ()

{

DISPLAY(i)

i <- i * 2

counter <- counter + 1

}

Which of the following replacements for will display the first 10 powers of 2?

counter < 10

98
New cards

(Pseudocode) You want to simulate rolling two six-sided dice. You are interested in how often you see a sum of 7 on the two dice. Which of the following would simulate counting the number of times one would see a sum of 7 on two dice rolls when rolling the dice 25 times?

Note that RANDOM(x,y) returns a random number in the range of [x,y]

q <- 0

REPEAT 25 TIMES

{

a <- RANDOM(1,6) + RANDOM(1,6)

IF (a = 7)

q <- q + 1

}

DISPLAY(q)

and

q <- 0

REPEAT 25 TIMES

{

a <- 0

REPEAT 2 TIMES

a <- a + RANDOM(1,6)

IF (a = 7)

q <- q + 1

}

DISPLAY(q)

99
New cards

Given that n and count are both of the same int, which statement is true about the following code

for (count = 1; count <= n; count++)

SOP(count);

count = 1;

while (count <= n)

{

SOP(count);

count++;

}

I and II are exactly equivalent for all input values n.

100
New cards

When reading from a file, which of the following scanner methods can be used as a condition of a loop as it returns true if there is more information in the file to be read?

hasNext