Lecture 2 Flashcards

1
Q

What are the 6 elements of writing a readable program?

A
  1. Structure
  2. Cohesion (put parts that belong together, together)
  3. Seperation ( whitespace)
  4. Indentation (tabs)
  5. Comments (javadoc)
  6. Logical Variable names (clearly expressing their role)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is “^” in java?

A

logical XOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is “~” in java?

A

bitwise complement (not …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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";
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly