Search Header Logo

11AE-CSC60-SBQ1

Authored by Computer Teacher

Other

11th Grade

Used 6+ times

11AE-CSC60-SBQ1
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

30 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

1) What are the two parts of an if statement?

a) A condition and a body
b) A check and an increment
c) An increment and a body
d) An increment and a return value

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

2) Which of the following statements is true about the if statement?

The if statement can have only one condition that evaluates to an integer value.
The if block is optional.
The else block is optional.
The if and else blocks should always be included within curly braces.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

3) Which of the following statements is correct about an if statement?

You must use braces if the body of an if statement contains only a single statement.
You can omit an else statement if there is no task defined in the else branch.
You cannot use braces if the body of an if statement contains only a single statement.
The number of opening braces can be different from the number of closing braces.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is the correct syntax for an if statement?

if (x < 10) { size = "Small"; } else (x < 20) { size = "Medium"; }

if (x < 10); { size = "Small"; } else (x < 20) { size = "Medium"; }

if (x < 10)

{ size = "Small";

}

else

{

size = "Medium";

}

if { size = "Small"; } else (x < 20) { size = "Medium"; }

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Assuming that the user provides 303 as input, what is the output of the following code snippet? int x; int y; x = 0; Scanner in = new Scanner(System.in); System.out.print("Please enter a number: "); y = in.nextInt(); if (y > 300) { x = y; } else { x = 0; } System.out.println("x: " + x);

x: 0
x: 300
x: 303
There is no output due to compilation errors.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Assuming that the user provides 99 as input, what is the output of the following code snippet? int a; int b; a = 0; Scanner in = new Scanner(System.in); System.out.print("Please enter a number: "); b = in.nextInt(); if (b > 300) { a = b; } else { a = 0; } System.out.println("a: " + a);

a: 0
a: 99
a: 100
a: 300

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

The following code snippet contains an error. What is the error? if (cost > 100); { cost = cost – 10; } System.out.println("Discount cost: " + cost);

Syntax error (won’t compile)
Logical error: use of an uninitialized variable
Logical error: if statement has do-nothing statement after if condition
Logical error: assignment statement does not show equality

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?