- Consider the following code snippet.
2. arrayOfInts[j] > arrayOfInts[j+1]
Which operators does the code contain?
- Consider the following code snippet.
4. int i = 10;
5. int n = i++%5;
- What are the values of i and n after the code is executed?
- What are the final values of i and n if instead of using the postfix increment operator (i++), you use the prefix version (++i))?
- To invert the value of a boolean, which operator would you use?
- Which operator is used to compare two values, = or == ?
- Explain the following code sample: result = someCondition ? value1 : value2;
- Consider the following code snippet:
2. arrayOfInts[j] > arrayOfInts[j+1]
Question: What operators does the code contain?
Answer: >, +
Answer: >, +
- Consider the following code snippet:
4. int i = 10;
5. int n = i++%5;
- Question: What are the values of i and n after the code is executed?
Answer: i is 11, and n is 0. - Question: What are the final values of i and n if instead of using the postfix increment operator (i++), you use the prefix version (++i))?
Answer: i is 11, and n is 1. - Question: To invert the value of a boolean, which operator would you use?
Answer: The logical complement operator "!". - Question: Which operator is used to compare two values, = or == ?
Answer: The == operator is used for comparison, and = is used for assignment. - Question: Explain the following code sample: result = someCondition ? value1 : value2;
Answer: This code should be read as: "If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result."
Walang komento:
Mag-post ng isang Komento