

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Class: CS 2401 โ Elementary Data Structures and Algorithms Length of session: 50 minutes Topic: Relational Operators
Because last week they just took a test, this section will provide a little fun. I would like to try out the game technique this week.
Questions:
a. What is the output for this code? double b = 3.0/7.0 + 2.0/7.0 + 2.0/7.0; if (b = = 1.0) System.out.println("Value of a equals 1.0"); else System.out.println("Value of a does not equal 1.0"); Answer: Value of a does not equal 1.0 (reference page 171 of textbook)
b. Given x and y are floating-point numbers, what does Math.abs(x-y) method do? What is the practical purpose of this method (clue: What is the purpose of this expression Math.abs(x-y) < 0.000001 )? Answer: This method will determine whether x equals to y.
c. What is the result of these two expressions? Explain your answers a. 8 < '5' b. 8 < 5 Answer: a. true (integer compare with char, using Unicode character set) b. false
d. What is the difference between equals() and compareTo()? Answer: equals() returns Boolean type compareTo() returns Integer type
e. Put these operators in precedence order: