Chapter 5: Decisions Flashcards
What does the if statement allow a program to do?
carry out different actions depending on the nature of the data to be processed
What does a relational operator test?
the relationship between two values
What relationship operators do programmers use to compare numbers?
<, <=, >, >=, ==, !=
Why don’t you check for equality when comparing floating-point numbers?
because they’re could be a rounding error. Instead, test whether they are close enough
What threshhold value do we say is “close enough”
10^(-14) OR 1e-14
T/F: use the == operator to compare strings
Fuck NO!
What method do you use to compare strings?
the equal method
What does the compareTo method do?
compares strings in lexographic order
What is ‘A’ in lexographic order?
65
What is ‘a’ in lexographic order
97
string1.compareTo(string2) == 0 returns true. What is true about the two strings?
they are identical
What would happen if you use the == method on objects?
it would test whether two object references are identical
What method should you use to compare the values of an object?
equals
What does the null reference refer to?
no object
What operator do you use to test whether an object is a null reference?
==