APCS quiz 4.1-4.5

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

assuming x is 3.6 and y is 4, state the value of the variable z after the following statement, z = Math.round (Math.sqrt (x));

2

assuming x is 3.6 and y is 4, state the value of the variable z after the following statement, z = Math.sqrt(y);

2

assuming x is 3.6 and y is 4, state the value of the variable z after the following statement, z = Math.round(x);

4

assuming x is 3.6 and y is 4, state the value of the variable z after the following statement, z = math.pow (y, 3);

64

What type of expression must the condition of an if statement contain

A boolean expression

What is the difference between an if statement and an if-else statement

An if statement is a one way decision. A single action is executed if the condition is true, otherwise control proceeds to the next statement after the if statement. An if-else statement provides a two way decision. The action following the condition is executed if the condition is true, otherwise the action after the else is executed.

given the following minispecifications, write expressions involving relational operators, if a, b, and c are the lengths of the sides of a triangle and c is the largest side, determine if the triangle is a right triangle (pythagorean theorem)

C == Math.round (Math.sqrt(a * a + b * b))

List the three components of a while loop

Continuation condition, loop body statements, and update statements

What happens if the condition of a while loop is false from the outset

It does not execute

Write code segments to print the following value in a terminal window, a random double between 1 and 10, inclusive

System.out.println ( (int) (10 * Math.random() + 1);

Write code segments to print the following value in a terminal window, a random integer between 1 and 20, inclusive

System.out.println( (int) (20 * Math.random() ) + 1 );

Describe the role of the curly braces in an if statement

They enclose a sequence of statements that are treated as a logical unit

When does a while loop terminate execution

When its condition becomes false

given the following minispecifications, write expressions involving relational operators, determine if an input value x is greater than 0

X > 0

Assuming x is 5 and y is 10 write the values of the following expression, x > y

false

given the following minispecifications, write expressions involving relational operators, determine if a given number of seconds equals a minute

numSeconds == 60

Assuming x is 5 and y is 10 write the values of the following expression, x - 2 != 0

true

Assuming x is 5 and y is 10 write the values of the following expression, x <= 10

true

Translate the following statement to equivalent statements that use extended assignment operators x = x * 2;

x *= 2;

Translate the following statement to a equivalent statement that do not use the extended assignment operators x *= x;

x = x * x;

Translate the following statement to a equivalent statement that do not use the extended assignment operators x += 5;

x = x + 5;

Translate the following statement to equivalent statements that use extended assignment operators y = y % 2;

y %= 2;


Kaugnay na mga set ng pag-aaral

earthquake test study/review guide

View Set

Further Practice on 'Key' Word Transformation 101-120 (Nina)

View Set

S1L1 HOLA ¿Qué tal? Vocabulario

View Set