click below
click below
Normal Size Small Size show me how
SCJA-drills-chap02
Question | Answer |
---|---|
What does assignment statements do? | Assignment statements assign values to variables. |
What do assign values to variables? | Assignment statements assign values to variables. |
What happens if an assignment statement do not return boolean type when used as the expression in an if statment? | Assignment statements that do not return boolean types will cause the compiler to report an error when used as the expression in an if statement. |
What, related to invalid literals, can cause a compiler error? | Trying to save an invalid literal to a declared primitive type variable will result in a compiler error. |
What are conditional statments used for? | Conditional statements are used for determining the direction of flow based on conditions. |
What are the conditional statements? | Types of conditional statements include the if, if-then, if-then-else, and switch statements. |
Where does the default statement of a switch can be placed? | The default case statement can be placed anywhere in the body of the switch statement. |
What must expressions used in if statments be evaluate to? | The expressions used in if statements must evaluate to boolean values, or the application will fail to compile. |
May Boolean wrapper classes be used in if statements? Motivate your answer? | Boolean wrapper classes are allowed as expressions in if statements since they are unboxed. |
What is unboxing, and what are the consequences related to their primitives? | Remember that unboxing is the automatic production of primitive values from their related wrapper classes when the primitive value is required. |
What are iteration statments? | Iteration statements are designed for iterating through pieces of code. |
Which iteration statements exist? | Iteration statements include the for loop, enhanced for loop, and the while and do-while statements. |
What are the main components of the for loop statement? | The for loop statement has main components that include an initialization part, an expression part, and an update part. |
What is the enhanced for loop statement used for? | The enhanced for loop statement is used for iteration through an iterable object or array. |
How would the code for a foreach loop look like in order to go through all of the String array str[]? | for (String s : str) { //code } |
What is the while loop statement based on? | The while loop statement is used for iteration based on a condition. |
Describe the do-while statement. | The do-while statement is used for iteration based on a condition. The body of this statement is always executed at least once. |
What the transfer of control statements do? | Transfer of control statements interrupt or stop the flow of execution. |
Which are the transfer of control statements? | The transfer of control statements include the continue, break, and return statements. |
What is the continue statement used for? | The continue statement is used to terminate the current iteration of a do-while, while, or for loop, and then continue with the next iteration. |
What is the break statement used for? | The break statement is used to exit the body of a switch statement or loop. |
What is the return statement used for? | The return statement is used to exit a method and return a specified value. |
What is a block? Give an example. | A block is a sequence of statements within braces—for example, { int x=0; int y=1 }. |
What are the pseudo-code used for? | Pseudo-code allows algorithm designers to express computer programming algorithms in a human-readable format. |
What does writing pseudo-code allow? | Writing pseudo-code allows for the quick and focused production of algorithms based on logic, not language syntax. |
How are pseudo-code algorithms written? | Java keywords and statement usage structures are used when implementing pseudo-code algorithms. |
Briefly describe the universally accepted standars for writing pseudo-code. | There are no universally accepted standards for writing pseudo-code. |