Question Description

Need help with my Programming question - I’m studying for my class.

I know the following Java relational expressions are valid. Can you explain to me why they are valid?

  • 5 <= 4+2

  • "Hello" != "World"

  • a < a - 0 (where a is an initialized non-local variable of integer type)


Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

1. 5 <= 4+ 2 : In Java, the arithmetic operators are evaluated first before the relational operators. So, this expression is just equivalent to 5 <= (4+2) which is 5 <= 6 . In words, you are testing if 5 is smaller than or equal to 6. Of course, 5 is smaller than 6 so this expression is true.

2. In this two strings are compared. As the two strings are not same and the expression itself says "hello" not equal to "world", thus this expression is also evaluated to be true.

3. In this same logic as the first one is applied, you evaluate a < a -0 so this is same as saying a < (a - 0) which is same as a < a. But, we all know that a is equal to a, hence this expression is evaluated to be false.

piratica (39)
Boston College

Top quality work from this tutor! I’ll be back!

Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.

Thank you! Reasonably priced given the quality


Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors