Lecture 2 Flashcards
1
Q
What are the 6 elements of writing a readable program?
A
- Structure
- Cohesion (put parts that belong together, together)
- Seperation ( whitespace)
- Indentation (tabs)
- Comments (javadoc)
- Logical Variable names (clearly expressing their role)
2
Q
What is the difference between & and && or | and ||
A
& and | check both sides and decide whether the logical operation is true, && and || don’t check the right-hand side if the left-hand side alone is enough to know the result of the operation
3
Q
What is “^” in java?
A
logical XOR
4
Q
What is “~” in java?
A
bitwise complement (not …)
5
Q
Give an example of a switch-statement
A
switch (grade) { case 10: result = "perfect"; break; case 9: case 8: case 7: case 6: result = "Pass"; break; default: result = "Fail"; }