Unit3.1
3.1 Boolean Expressions
Java’s relational operators
- equal to: ==
- not equal to: !=
- less than: <
- greater than: >
- less than or equal to: <=
- greater than or equal to >=
Hack!
int myAge = 15;
int otherAge = 45;
using these integers, determine weather the following statements are True or False
Strings
popcorn hack
whats wrong with this code? (below)
String myName = "Alisha"; //names should be in parantheses because they are strings
myName != "Anika";
myName == "Alisha";
true
comparison of string objects should be done using String methods, NOT integer methods.
- .equal
- compare to
String myName = "Alisha";
boolean areNamesEqual = myName.equals("Alisha");
if (areNamesEqual) {
System.out.println("True");
} else {
System.out.println("False");
}
True
homework question
what is the precondition for num?
The preconditions for the num is for it to be a non-negative integer and it should have between one and six digits!