Search Header Logo

1.1.5 Intro to programming quiz review

Authored by Michael Courtright

Computers

9th - 12th Grade

Used 4+ times

1.1.5 Intro to programming quiz review
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following code segment in the image

1

0.0

1.0

8.0

0.0

Answer explanation

In the following statements, the values of variables a, b, and c are plugged into this expression: a b / c a / b c

int a = 5;

int b = 4;

int c = 2;

double x = a b / c a / b c;

The expression is evaluated using the precedence of operators, as follows:

a b / c a / b c

= 5 4 / 2 5 / 4 2 // 5 / 4 is 1, as it is integer division.

= 20 / 2 1 * 2 // 20 / 2 is 10, as

it is integer division.

= 10 2

= 8

8 is assigned to double type variable x, therefore the output is 8.0.

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Answer the question in the image

10 11 45 25

10 11 46 25

10 11 47 26

10 10 46 25

10 10 40 20

Answer explanation

The execution of the statements is as follows:

int score = 10; // The value of 10 is assigned to the variable score.

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

// The value of score, 10, is displayed and followed by a space.

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

/* The value of score, 10, is then incremented to 11. */

score *= 2;

// The value of score, 11, is doubled, making it 22.

System.out.print(++score*2  + " ");

/* The value of score is incremented to 23 first, so 46 is displayed.

*/ int penalty = 4;

// The value of 4 is assigned to penalty. score += penalty/2;

// The result of 4/2 = 2 is added to score, making it 25.

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

// 25 is displayed.

So, the complete output is 10 10 46 25.

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

How many bytes are occupied by a variable of the int data type in the Java programming language?

1

2

4

8

16

Answer explanation

An int data type variable in Java occupies 4 bytes of memory.

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

final float PI = 3.14;

System.out.println("The volume of a cylinder is: " + (PI*radius*radius*height) );

int PI = 3.14;

System.out.println("The volume of a cylinder is: "+ (PI*radius*radius*height) );

final double pi = 3.14;

System.out.println("The volume of a cylinder is: "+ (PI*radius*radius*height) );

final double PI = 3.14;

System.out.println("The volume of a cylinder is: "+ (PI*radius*radius*height) );

final double PI;

System.out.println("The volume of a cylinder is: "+ (PI*radius*radius*height) );

Answer explanation

The value of pi is constant, so the desired output requires the usage of the final keyword for declaring a named constant.

Choice D declares a named constant PI with the appropriate data type and uses it to display the output as required.

Choice A is not correct, as the declaration statement is assigning a double value to a float type constant, which will generate a syntax error. Recall that floating type literals are of the double data type by default in Java.

Choice B does not declare a named constant.

Choice C will generate a syntax error, as the declaration statement declares the named constant as pi and uses PI in System.out.println().

Choice E will generate a syntax error, as the declaration statement does not assign a constant value.

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following statements is true?

Integer variables cannot be used as an operand for the / operator.

The data type of a variable is used to determine where the variable is stored in computer memory when the program is executed.

In Java, the data types in the declaration statements of named constants are needed only for documentation purposes.

The data type of a variable determines the kind of operations that can be performed on the variable.

Variables of the float data type are represented in memory as strings of decimal digits with a decimal point and an optional sign.

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

Answer the question in the image.

Happy New YearWelcome 2022

Happy New Year Welcome2022

HappyNewYearWelcome2022

Welcome 2022 Happy New Year

Happy New Year Welcome 2022

7.

MULTIPLE CHOICE QUESTION

1 min • 5 pts

Which of the following data types is the correct option for creating a variable that can be assigned the numeric value 345.67?

double

boolean

int

byte

char

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?