What happens if the condition in an if-statement is false?
The block of code inside the if-statement is skipped.
What does the Structure Theorem state?
It is possible to write ANY computer program using only three basic control structures.
1/150
p.9
If-Statement

What happens if the condition in an if-statement is false?

The block of code inside the if-statement is skipped.

p.2
Structure Theorem

What does the Structure Theorem state?

It is possible to write ANY computer program using only three basic control structures.

p.7
Logical Operators

What does the expression ! exp1 represent?

The negation of the boolean expression exp1.

p.7
Logical Operators

What is the result of ! (k==5) when k=4?

true.

p.3
Boolean Condition Checking

What is the primary focus of Part 1?

Boolean condition checking.

p.25
Switch Statement

What data types can the switch expression have?

byte, short, int, or char (and String from JDK7).

p.14
If-Else Statement

What does the program output after determining the grade?

It outputs the user's score and grade.

p.26
Switch Statement

What output is produced when the value is 3?

It prints 'Three'.

p.28
Switch Statement

How can the program be rewritten to use only 4 sayHello() calls while maintaining the same functionality?

Use a single sayHello() call in each case and repeat it based on the value input.

p.12
If-Statement

What message is displayed if the score is 40 or above?

Congratulations! You got a pass.

p.9
If-Statement

What is the primary function of an if-statement?

To execute a block of code based on a condition being true.

p.13
If-Else Statement

What happens if the boolean condition in an if-else statement evaluates to true?

statement_A is executed.

p.28
Switch Statement

What is the purpose of the switch statement in the provided Java code?

To execute different actions based on the value input by the user.

p.25
Switch Statement

What does the switch statement do?

It tries to match which case has the same value as the switch expression.

p.26
Switch Statement

What is the purpose of the switch statement in the provided Java code?

To execute different blocks of code based on the value of the variable 'value'.

p.13
If-Else Statement

What is the general structure of an if-else statement?

if (condition) statement_A else statement_B next_statement;

p.16
Nested If Statements

What is the syntax for a basic if statement?

if (condition) statement; next_statement;

p.24
Switch Statement

How does a switch statement differ from an if-else statement?

A switch statement is typically used for multiple discrete values, while if-else is used for ranges or conditions.

p.13
If-Else Statement

What happens if the boolean condition in an if-else statement evaluates to false?

statement_B is executed.

p.14
If-Else Statement

What happens if the score is 40 or higher?

The grade is set to 'P' and a congratulatory message is printed.

p.29
Structure Theorem

What does '29 (C) VTC' refer to?

It appears to be a reference or code related to a specific document or course.

p.25
Switch Statement

What is the structure of a switch statement?

switch (expression) { case value1: statement(s); break; case value2: statement(s); break; … default: statement(s); }

p.21
Nested If Statements

What does the first condition check in the nested if statement?

If examMark is greater than 89.

p.5
Logical Operators

What is the result of the expression (j==3)&&(n>m) when j=3, n=5, and m=4?

True.

p.22
Conditional Operator

In the expression 'larger = (num1 > num2) ? num1 : num2;', what does 'num1' represent?

The value when the condition is true.

p.11
If-Statement

What does the program output regardless of the score?

Your score is followed by the actual score.

p.9
If-Statement

Can an if-statement be used to check multiple conditions?

Yes, by using nested if-statements or combining conditions with logical operators.

p.28
Switch Statement

How many times does the method sayHello() get called for case 2?

Twice.

p.8
Operator Precedence

What happens if operator precedence is not considered?

The result of an expression may be incorrect due to unintended order of operations.

p.3
Boolean Condition Checking

What does 'VTC' stand for in the context of this content?

Vocational Training Council.

p.16
Nested If Statements

What happens if the boolean condition in a nested if statement evaluates to true?

The statement is executed.

p.8
Operator Precedence

What is the general rule for operator precedence in C?

Operators with higher precedence are evaluated before operators with lower precedence.

p.16
Nested If Statements

Can the statement in an if statement be another if statement?

Yes, the statement itself can be another if-statement.

p.11
If-Statement

What condition is checked in the SimpleIf program?

If the score is greater than or equal to 40.

p.6
Logical Operators

What does the logical operator OR (||) do?

It combines two boolean expressions and returns false only if both are false.

p.12
If-Statement

What will the output be if the user inputs a score of 30?

Your score is 30.

p.17
Nested If Statements

What is the second condition checked if the first condition is true?

If the score is greater than or equal to 75.

p.17
Nested If Statements

What does the program output when the score is 50?

'Your score is 50'.

p.18
If-Else Statement

What is printed to the console regardless of the score?

System.out.println("Your score is " + score);

p.4
Relational Operators

What is the result of 'n <= m' when n=5 and m=4?

false.

p.2
Structure Theorem

How many basic control structures are defined by the Structure Theorem?

Three.

p.3
Boolean Condition Checking

Who prepared the content for Part 1?

sm-lau@vtc.edu.hk.

p.11
If-Statement

What does the SimpleIf program prompt the user for?

The user's score.

p.23
Conditional Operator

What does the expression 'isEven = (num % 2 == 0) ? true : false;' do?

It assigns true to isEven if num is even, otherwise false.

p.27
Switch Statement

What does the switch statement in the provided Java code do?

It evaluates the variable 'value' and executes the corresponding case block.

p.17
Nested If Statements

What is the first condition checked in the NestedIf program?

If the score is greater than or equal to 40.

p.23
Boolean Condition Checking

What is the condition checked to determine if num is even?

The condition is 'num % 2 == 0'.

p.5
Logical Operators

What is the result of the expression (j>k)&&(j!=3) when j=3 and k=4?

False.

p.17
Nested If Statements

What does the program output when the score is 30?

'Your score is 30'.

p.15
If-Else Statement

What is the significance of using curly braces { } in the else-part?

To enclose multiple statements within the else block.

p.4
Relational Operators

What is the result of 'j != k' when j=3 and k=4?

true.

p.4
Relational Operators

What is the result of 'k >= m' when k=4 and m=4?

true.

p.10
If-Statement

What occurs if the boolean condition in a simple if statement evaluates to false?

The statement is skipped.

p.10
If-Statement

What does the program do after evaluating the if statement?

It proceeds to execute the next_statement.

p.5
Logical Operators

What does the logical operator AND (&&) do?

It returns true only if both boolean expressions are true.

p.23
Conditional Operator

What is the purpose of 'countA += (ch == 'A') ? 1 : 0;'?

It increments countA by 1 if ch is 'A', otherwise it adds 0.

p.6
Logical Operators

What is the result of the expression (j==3)||(k==5) if j=3 and k=4?

True, because j==3 is true.

p.21
Nested If Statements

What will be printed if examMark is greater than 59 but less than or equal to 69?

The output will be 'D'.

p.27
Switch Statement

What does the program print after the switch statement?

It prints 'after switch'.

p.4
Relational Operators

What does the operator '<=' signify?

Less than or equal to.

p.7
Logical Operators

What is the result of ! (j==3) when j=3?

false.

p.29
Structure Theorem

Who prepared the document associated with '29 (C) VTC'?

sm-lau@vtc.edu.hk.

p.10
If-Statement

What is the syntax of a simple if statement?

if (condition) statement; next_statement;

p.26
Switch Statement

What is the data type of the variable 'value' in the code?

int.

p.11
If-Statement

What message is displayed if the score is 40 or higher?

You got a pass.

p.15
If-Else Statement

What is the purpose of the IfElseEg2 program?

To determine a grade based on the score input by the user.

p.21
Nested If Statements

What happens if examMark is greater than 79 but less than or equal to 89?

The output will be 'B'.

p.12
If-Statement

What will the output be if the user inputs a score of 80?

Congratulations! You got a pass. Your score is 80.

p.23
If-Statement

What happens if ch is 'A' in the given code?

countA is incremented by 1.

p.15
If-Else Statement

What data type is used for the variable 'grade'?

char.

p.4
Relational Operators

What is the result of 'm > k' when m=4 and k=4?

false.

p.9
If-Statement

What is the syntax structure of a basic if-statement?

if (condition) { // code to execute }

p.12
If-Statement

What input does the SimpleIf2 program ask for?

It asks for a score from the user.

p.20
If-Else Statement

What does an else-part attach to in an if-else statement?

The nearest if that has not yet been paired.

p.5
Logical Operators

What is the result of the expression (j==3)&&(k==5) when j=3 and k=4?

False.

p.27
Switch Statement

What happens if the input value is 1?

It prints 'One' and continues to execute the next case without a break.

p.1
If-Statement

What is the significance of selection structures in programming?

They allow for decision-making in code execution.

p.4
Relational Operators

What does the operator '!=' signify?

Not equal to.

p.10
If-Statement

What happens if the boolean condition in a simple if statement evaluates to true?

The statement is executed.

p.24
Switch Statement

What is the purpose of a switch statement in programming?

To execute different parts of code based on the value of a variable.

p.26
Switch Statement

What is printed after the switch statement regardless of the case?

'after switch'.

p.24
Switch Statement

What is required for each case in a switch statement?

Each case must end with a break statement to prevent fall-through.

p.17
Nested If Statements

What output does the program produce if the score is 75?

'Congratulations! Your score is 75'.

p.18
If-Statement

What is the purpose of the 'if' statement in programming?

To execute a block of code based on a boolean condition.

p.4
Relational Operators

What do relational operators return?

Either true or false.

p.18
Boolean Condition Checking

What is the condition checked in the first if statement?

score >= 40

p.7
Logical Operators

What is the NOT operator?

A unary operator that negates the value of a boolean expression.

p.14
If-Else Statement

What is the purpose of the IfElseEg program?

To determine a grade based on the score input by the user.

p.8
Operator Precedence

Why is operator precedence important in programming?

It affects the outcome of expressions by determining which operations are performed first.

p.26
Switch Statement

What happens when the value is 1 in the switch statement?

It prints 'One'.

p.28
Switch Statement

What is the output of the program if the user inputs 3?

Hello Hello Hello Bye!

p.25
Switch Statement

What is executed if no match is found in a switch statement?

The default case will be executed.

p.22
Conditional Operator

What does the conditional operator return?

A value.

p.12
If-Statement

What does the program print regardless of the score?

Your score is followed by the actual score.

p.12
If-Statement

What should be used to enclose multiple statements in an if condition?

A pair of curly braces { }.

p.6
Logical Operators

When will the expression (j==3)||(n>m) evaluate to true?

When j is equal to 3 or n is greater than m.

p.23
Conditional Operator

What does 'y = (x < 0) ? -x : x;' achieve?

It stores the absolute value of x into y.

p.5
Logical Operators

What is the result of the expression (j>k)&&(n>m) when j=3, k=4, n=5, and m=4?

False.

p.6
Logical Operators

What is the result of the expression (j>k)||(j!=3) if j=3 and k=4?

False, because both j>k and j!=3 are false.

p.4
Relational Operators

What is the result of the expression 'k == m' when k=4 and m=4?

true.

p.8
Operator Precedence

What is operator precedence?

The rules that determine the order in which different operators are evaluated in an expression.

p.8
Operator Precedence

Can parentheses affect operator precedence?

Yes, parentheses can override the default precedence rules.

p.26
Switch Statement

What does the default case in the switch statement handle?

It handles any value that is not 1, 2, or 3, printing 'Invalid value'.

p.1
If-Statement

What are selection structures used for in programming?

To execute different code blocks based on certain conditions.

p.1
If-Statement

What is the purpose of an If-Statement?

To perform a specific action if a condition is true.

p.20
If-Else Statement

What is the consequence of incorrectly pairing else with an if statement?

The code will not function as intended.

p.15
If-Else Statement

What score is required to receive a grade of 'P'?

A score of 40 or higher.

p.20
If-Else Statement

What is the purpose of the next_statement in the provided code?

It indicates the next line of code to execute after the if-else structure.

p.11
If-Statement

What is the output when the score is 80?

You got a pass. Your score is 80.

p.23
If-Else Statement

What value is assigned to y if x is negative?

The negative of x is assigned to y.

p.4
Relational Operators

What is the result of the expression 'j == k' when j=3 and k=4?

false.

p.13
If-Else Statement

What does the program do after executing either statement_A or statement_B?

It proceeds to execute the next_statement.

p.14
If-Else Statement

What grade is assigned if the score is below 40?

The grade is set to 'F'.

p.12
If-Statement

What is the purpose of the SimpleIf2 program?

To check if a score is passing (40 or above) and print a message accordingly.

p.22
Conditional Operator

What is the conditional operator similar to?

An if-else statement.

p.17
Nested If Statements

What happens if the score is less than 40 in the NestedIf program?

The program does not print 'Congratulations!' and only shows the score.

p.22
Conditional Operator

In the expression 'larger = (num1 > num2) ? num1 : num2;', what does 'num2' represent?

The value when the condition is false.

p.21
Nested If Statements

What is the output for an examMark greater than 69 but less than or equal to 79?

The output will be 'C'.

p.4
Relational Operators

What are relational operators?

Binary operators for comparing two values.

p.27
Switch Statement

What is the output of the program when the input value is 1?

It prints 'One', 'Two', and 'Three' due to fall-through behavior.

p.28
Switch Statement

What will be printed if the user inputs a value not between 1 and 4?

Invalid value.

p.25
Switch Statement

What happens when the first match is found in a switch statement?

The statement(s) starting just under the match are executed until a break statement.

p.25
Switch Statement

What occurs if there is no match case and no default case in a switch statement?

Nothing is executed.

p.1
Nested If Statements

What is a Nested If Statement?

An If statement inside another If statement, allowing for multiple conditions to be checked.

p.18
If-Else Statement

What does the 'else' keyword do in an if-else statement?

It specifies a block of code to execute if the condition in the if statement is false.

p.15
If-Else Statement

What will the program output if the user inputs a score of 60?

Congratulations! Your score is 60. Your grade is P.

p.27
Switch Statement

What will be printed if an invalid value is entered?

It will print 'Invalid value'.

p.14
If-Else Statement

What is the input method used to get the score in the program?

The program uses a Scanner to read input from the keyboard.

p.29
Structure Theorem

What does 'END' signify in the context of a document?

It typically indicates the conclusion or termination of the document.

p.16
Nested If Statements

What is the structure of a nested if statement?

if (condition_2) statement_2;

p.26
Switch Statement

What library is imported to use the Scanner class in the code?

java.util.*.

p.20
Nested If Statements

What is the structure of a nested if statement?

if (condition) { if (condition_2) statement_2; } else statement_C next_statement;

p.1
If-Else Statement

What is an If-Else Statement?

A control structure that executes one block of code if a condition is true and another block if it is false.

p.18
If-Else Statement

What is the output when the score is 75 or higher?

System.out.println("Congratulations!");

p.4
Relational Operators

What is the result of the expression 'n > m' when n=5 and m=4?

true.

p.17
Nested If Statements

What is the purpose of the NestedIf program?

To evaluate a score and provide feedback based on conditions.

p.22
Conditional Operator

How is the conditional operator syntax structured?

condition ? expression_if_true : expression_if_false.

p.24
Switch Statement

What happens if no case matches in a switch statement?

The default case, if provided, will be executed.

p.21
Nested If Statements

What output is produced if examMark is greater than 89?

The output will be 'A'.

p.24
Switch Statement

Can a switch statement handle multiple cases for the same block of code?

Yes, multiple cases can be grouped together to execute the same code block.

p.11
If-Statement

What is the output when the score is 30?

Your score is 30.

p.6
Logical Operators

What is the result of the expression (j>k)||(n>m) if j=3, k=4, n=5, and m=4?

True, because n>m is true.

p.21
Nested If Statements

What is the output if examMark is 59 or below?

The output will be 'F'.

p.18
Boolean Condition Checking

What is the second condition checked in the nested if statement?

score >= 75

p.27
Switch Statement

What is the output when the input value is 3?

It prints 'Three' and then breaks out of the switch statement.

p.27
Switch Statement

What is the purpose of the 'break' statement in the switch cases?

It prevents fall-through by exiting the switch after executing the matched case.

p.15
If-Else Statement

What data type is used for the variable 'score'?

int.

p.15
If-Else Statement

What message is displayed if the score is below 40?

Work hard!

p.18
If-Else Statement

What happens if the score is between 40 and 75?

System.out.println("You got a pass.");

p.4
Relational Operators

What is the result of 'm >= n' when m=4 and n=5?

false.

Study Smarter, Not Harder
Study Smarter, Not Harder