Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

17 Questions Flow of Control Exercise - Computer Programming | CSC 3405, Study notes of Computer Science

Material Type: Notes; Professor: Wei; Class: Intro Computer Programming; Subject: Computer Science; University: Saint Joseph's University; Term: Fall 2006;

Typology: Study notes

Pre 2010

Uploaded on 08/16/2009

koofers-user-k1j
koofers-user-k1j 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 3
Flow of Control
 Multiple ChoiceMultiple Choice
1) An if selection statement executes if and only if:
(a) the Boolean condition evaluates to false.
(b) the Boolean condition evaluates to true.
(c) the Boolean condition is short-circuited.
(d) none of the above.
2) A compound statement is enclosed between:
(a) [ ]
(b) { }
(c) ( )
(d) < >
3) A multi-way if-else statement
(a) allows you to choose one course of action.
(b) always executes the else statement.
(c) allows you to choose among alternative courses of action.
(d) executes all Boolean conditions that evaluate to true.
4) The controlling expression for a switch statement includes all of the following types except:
(a) char
(b) int
1
pf3
pf4
pf5

Partial preview of the text

Download 17 Questions Flow of Control Exercise - Computer Programming | CSC 3405 and more Study notes Computer Science in PDF only on Docsity!

Chapter 3

Flow of Control

 Multiple Choice

  1. An if selection statement executes if and only if: (a) the Boolean condition evaluates to false. (b) the Boolean condition evaluates to true. (c) the Boolean condition is short-circuited. (d) none of the above.
  2. A compound statement is enclosed between: (a) [ ] (b) { } (c) ( ) (d) < >
  3. A multi-way if-else statement (a) allows you to choose one course of action. (b) always executes the else statement. (c) allows you to choose among alternative courses of action. (d) executes all Boolean conditions that evaluate to true.
  4. The controlling expression for a switch statement includes all of the following types except: (a) char (b) int 1

(c) byte (d) double

  1. To compare two strings lexicographically the String method ____________ should be used. (a) equals (b) equalsIgnoreCase (c) compareTo (d) ==
  2. When using a compound Boolean expression joined by an && (AND) in an if statement: (a) Both expressions must evaluate to true for the statement to execute. (b) The first expression must evaluate to true and the second expression must evaluate to false for the statement to execute. (c) The first expression must evaluate to false and the second expression must evaluate to true for the statement to execute. (d) Both expressions must evaluate to false for the statement to execute.
  3. The OR operator in Java is represented by: (a)! (b) && (c) | | (d) None of the above
  4. The negation operator in Java is represented by: (a)! (b) && (c) | |

(d) Pseudocode

  1. When the number of repetitions are known in advance, you should use a ___________ statement. (a) while (b) do…while (c) for (d) None of the above
  2. A ___________ statement terminates the current iteration of a loop. (a) Break (b) Continue (c) Switch (d) Assert
  3. Common loop errors are: (a) Off-by-one (b) Infinite loops (c) Both a and b (d) None of the above
  4. To terminate a program, use the Java statement: (a) System.quit(0); (b) System.end(0); (c) System.abort(0); (d) System.exit(0);

5

  1. Good debugging techniques include: (a) Inserting output statements in your program. (b) Tracing variables (c) Using an IDE debugger (d) All of the above

 True/False

  1. An if-else statement chooses between two alternative statements based on the value of a Boolean expression.
  2. You may omit the else part of an if-else statement if no alternative action is required.
  3. In a switch statement, the choice of which branch to execute is determined by an expression given in parentheses after the keyword switch.
  4. In a switch statement, the default case is always executed.
  5. Not including the break statements within a switch statement results in a syntax error.
  6. The equality operator (==) may be used to test if two string objects contain the same value.
  7. Boolean expressions are used to control branch and loop statements.
  8. The for statement, do…while statement and while statement are examples of branching mechanisms.
  9. When choosing a sentinel value, you should choose a value that would never be encountered in the input of the program.
  10. An algorithm is a step-by-step method of solution.
  11. The three expressions at the start of a for statement are separated by two commas.
  12. An empty statement is defined as a loop that runs forever.

 Short Answer/Essay

What output will be produced by the following code? public class SelectionStatements { public static void main(String[] args) { int number = 24; if (number % 2 == 0) System.out.print("The condition evaluated to true!");

7 System.out.println("The value of x is:" + x); while (x > 0) { x++; } System.out.println("The value of x is:" + x); }

  1. Discuss the differences between the break and the continue statements when used in looping mechanisms.
  2. Write a complete Java program that prompts the user for a series of numbers to determine the smallest value entered. Before the program terminates, display the smallest value.
  3. Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.