nerdexam
Oracle

1Z0-851 · Question #85

Given: public class Spock { public static void main(String[] args) { Long tail = 2000L; Long distance = 1999L; Long story = 1000L; if((tail > distance) ^ ((story 2) == tail)) System.out.print("1")…

The correct answer is E. No output is produced. ^ - XOR - returns true if (false ^ true), (true ^ false)

Analyzing and Troubleshooting System Problems

Question

Given: public class Spock { public static void main(String[] args) { Long tail = 2000L; Long distance = 1999L; Long story = 1000L; if((tail > distance) ^ ((story * 2) == tail)) System.out.print("1"); if((distance + 1 != tail) ^ ((story * 2) == distance)) System.out.print("2"); } } What is the result?

Options

  • A1
  • B2
  • C12
  • DCompilation fails.
  • ENo output is produced.
  • FAn exception is thrown at runtime.

How the community answered

(50 responses)
  • A
    2% (1)
  • B
    8% (4)
  • D
    4% (2)
  • E
    84% (42)
  • F
    2% (1)

Explanation

^ - XOR - returns true if (false ^ true), (true ^ false)

Topics

#Java XOR operator#boolean logic#Long arithmetic#operator precedence

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice