Biyernes, Hulyo 22, 2011

Q&A Java Language 3

  1. Consider the following code snippet.
2.  arrayOfInts[j] > arrayOfInts[j+1]
Which operators does the code contain?
  1. Consider the following code snippet.
4.  int i = 10;
5.  int n = i++%5;
    1. What are the values of i and n after the code is executed?
    2. What are the final values of i and n if instead of using the postfix increment operator (i++), you use the prefix version (++i))?
  1. To invert the value of a boolean, which operator would you use?
  2. Which operator is used to compare two values, = or == ?
  3. Explain the following code sample: result = someCondition ? value1 : value2;

  1. Consider the following code snippet:
2.  arrayOfInts[j] > arrayOfInts[j+1]
Question: What operators does the code contain?
Answer:
>, +
  1. Consider the following code snippet:
4.  int i = 10;
5.  int n = i++%5;
    1. Question: What are the values of i and n after the code is executed?
      Answer:
      i is 11, and n is 0.
    2. 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.
  1. Question: To invert the value of a boolean, which operator would you use?
    Answer: The logical complement operator "!".
  2. Question: Which operator is used to compare two values, = or == ?
    Answer: The
    == operator is used for comparison, and = is used for assignment.
  3. 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