Comp Sci Principles unit 4

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

symbol for comparison operators: EQUAL NOT EQUAL LESS THAN GREATER THAN LESS THAN OR EQUAL GREATER THAN OR EQUAL

EQUAL == NOT EQUAL != LESS THAN < GREATER THAN > LESS THAN OR EQUAL <= GREATER THAN OR EQUAL >=

Determine whether the following expression would evaluate to true or false. a AND (b OR c) a. (a AND b) OR c b. (a AND b) OR (a AND c) c. (a AND b) AND (a AND c) d.(b AND c) OR a

b. (a AND b) OR (a AND c)

How can we check if a variable num is even? a. num.isEven() will be true b. (num % 2 == 0) will be true c. (num % 2 == 0) will be false d. (num / 2 == 0) will be true

b. (num % 2 == 0) will be true

which of the following is not a valid term for a boolean? a. true b. false c. yes d. all of the above are valid

c. yes

what symbol represents the or operator JavaScript? a. OR b. or c. | d. ||

d. ||

for loop code format

for(var i = 0; i < COUNT; i++){ //code to execute count times }

when do else statements print in an if else statement

if the if statement is false, it prints the else statement

symbol for logical operators: NOT OR AND

NOT ! OR || AND &&

randomizer format for int, boolean, float, and color

Randomizer.nextInt(low, high); Randomizer.nextBoolean(); Randomizer.nextFloat(low, high); Randomizer.nextColor();

What will be the value of sum after this code runs? var START = 1; var END = 4; function start(){ var sum = 0; for(var i = START; i <= END; i++){ sum += i; } } a. 10 b. 4 c. 1 d. 40

a. 10

A summer camp offers a morning session and an afternoon session. The list morningList contains the names of all children attending the morning session, and the list afternoonList contains the names of all children attending the afternoon session. Only children who attend both sessions eat lunch at the camp. The camp director wants to create lunchList, which will contain the names of children attending both sessions. The following code segment is intended to create lunchList, which is initially empty. It uses the procedure IsFound (list, name), which returns true if name is found in list and returns false otherwise. FOR EACH child IN morningList { <MISSING CODE> } a. IF (IsFound (afternoonList, child)) { APPEND (lunchList, child) } b. IF (IsFound (lunchList, child)) { APPEND (afternoonList, child) } c. IF (IsFound (morningList, child)) { APPEND (lunchList, child) } d. IF ((IsFound (morningList, child)) OR (IsFound (afternoonList, child))) { APPEND (lunchList, child) }

a. IF (IsFound (afternoonList, child)) { APPEND (lunchList, child) }

what is the term for the value that signals the end of the user input? a. sentinel b. break c. -1 d. done

a. sentinel

After the following code runs, what is the value of isWeekend? var isSaturday = true; var isSunday = false; var isWeekend = isSaturday || isSunday; a. true b. false c. "isWeekend" d. "isSaturday || isSunday"

a. true

What is the proper operator for "not equals" in JavaScript? a. =! b. != c. ~= d. NOT EQUALS

b. !=

How many times will this program print "hello"? var i = 10; while (i > 0) { println("hello"); i--; } a. 0 b. 10 c. i d. this code will loop infinitely

b. 10

How many times will the following code print "hello"? for (var i = 3; i < 8; i++) { println("hello"); } a. 3 b. 5 c. 6 d.8

b. 5

How many times will the following program print "hello"? for (var i = 0; i < 5; i++) { println("hello"); } a. 4 b. 5 c. 6 d. i

b. 5

What is the proper way to compare if two values are equal in a boolean expression in JavaScript? a. = b. == c. EQUALS d. is

b. ==

consider the code segment below if onTime display "hello." else if absent display "is anyone there?" else display "better late than never." If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment? a. is anyone there? b. better late than never. c. hello. is anyone there? d. hello. better late than never.

b. better late than never.

what statement can we use inside of a loop to end it? a. println b. break c. for d. else

b. break

Determine whether the following expression would evaluate to true or false. 7=6 OR 8≥4 a. false b. true

b. true

Which of the following is a good example of a proper constant variable name? a. var max_value = 100; b. var MAX_VALUE = 100; c. var Max_Value = 100; d. var maxValue = 100;

b. var MAX_VALUE = 100;

Which of the following Boolean expressions is equivalent to the expression (a OR b) AND NOT (c OR d) a. (a OR b) AND ((NOT c) OR (NOT d)) b. (a AND NOT (c OR d)) OR b c. (a OR b) AND (NOT c) AND (NOT d) d. NOT (a AND b) AND NOT (c OR d)

c. (a OR b) AND (NOT c) AND (NOT d)

How many possible values can Randomizer.nextBoolean() return? a. 0 b. 1 c. 2 d. 3

c. 2

How many times will the following code print "hello"? for (var i = 0; i < 8; i += 2) { println("hello"); } a. 0 b. 2 c. 4 d.8

c. 4

In the following code block, assume that the variables rainy and tooCold are boolean. IF (NOT (rainy OR tooCold)) { DISPLAY("It's a good beach day") } a. IF (( NOT rainy) OR (NOT tooCold)){ DISPLAY("It's a good beach day") } b. IF (( NOT rainy) AND tooCold) { DISPLAY("It's a good beach day") } c. IF (( NOT rainy) AND (NOT tooCold)) { DISPLAY("It's a good beach day") } d. IF (rainy AND tooCold) { DISPLAY("It's a good beach day") }

c. IF (( NOT rainy) AND (NOT tooCold)) { DISPLAY("It's a good beach day") }

What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise? a. if statement b. break statement c. if/else statement d. for loop

c. if/else statement

which of the following is correct loop and a half structure? a. while(condition){ //code } b. for(var i = 0; i <= 1.5; i++){ //code } c. while(true){ //code if(condition){ break; } //code } d. for(var i = 0; i < 2; i++){ //code break; //code }

c. while(true){ //code if(condition){ break; } //code }

what two logical operators let us do to boolean expressions

connect and modify

what symbol represents the and operator in JavaScript? a. AND b. and c. & d. &&

d. &&

In the following code, what will be the last number to print to the screen before the program finishes? for (var i = 0; i < 10; i++) { if (i % 2 == 0) { println(i); } else { println(2 * i); } } a. 10 b. 20 c. 9 d. 18

d. 18

Which of the following returns a random number between 1 and 10? a. randomInt(1, 10) b. randInt(1, 10) c. Randomizer.int(1, 10) d. Randomizer.nextInt(1, 10)

d. Randomizer.nextInt(1, 10)

Why do we use constant variables? a. to avoid having "magic numbers" in our code b. to give values a readable name, so their purpose is clear c. to let us easily change the behavior of our program by only having to change a value in one place d. all of the above

d. all of the above

How many times will this program print "hello"? var i = 50; while (i < 100) { println("hello"); } a. 0 b. 50 c. 100 d. this code will loop infinitely

d. this code will loop infinitely

what will be printed after this is run function start var isWeekend = true; var isVacation = false; var isSchool; if(isWeekend || isVacation) isSchool = false; println(isSchool); else isSchool = true; println(isSchool);

false

how to count by twos in a for loop

i += 2 instead of i++

how to count down in a for loop

i-- instead of i++

when do if statements print

if the expression is true

what does a break statement do

it quits the loop

what does a sentinel do

it tells us when to stop the loop for example: var SENTINEL = -1; var sum = 0 while(true){ var num = readInt("Enter a number: "); if(num == SENTINEL){ break; } sum += num; }

what do comparison operators let us do

they let us compare two values

A boolean value can either be ________ or __________

true or false

how can you identify a loop and a half statement

when there is a break statement in the loop

when do while loops execute

while a condition is true


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

Comparing aa Function and its Inverse

View Set

Chapter 7- Life Insurance Underwriting and Policy Issue

View Set

Chapter 07: Legal Dimensions of Nursing Practice

View Set