Lec 3: Numbers and Math Flashcards
What is a literal
A constant value that appears directly in a program
What is the storage size of a byte?
8 bit signed
What is the storage size of a short?
16 bit signed
What is the storage size of an int?
32 bit signed
What is the storage size of a long
64 bit signed
What is the storage size of a float
32 bit IEEE 754
What is the storage size of a double
64 bit IEEE 754
True or false: Int variables store numbers accurately?
True
True or false: float numbers store numbers accurately?
False
System.out.println(1.0-0.9); gives 0.09999999998 and not 0.1
What data type is truncated when divided with itself?
Int
5/2 yields 2
What is truncated
not to be mistaken with rounding
returns the int down
5/2 yields 2
math operative conversion rules
If one operand is double, the other is converted to double
otherwise if one is float, the other is converted into float
otherwise if one is long, the other is converted to long
True or False: When casting a double to int, it truncates
True
Operator precedence
- (), var++, var–
- ++var, –var, +, - (unary plus and minus), ! (not)
- (type) casting
- *, /, % (multiplication, division, and remainder)
- +, - (binary addition and subtraction)
- <, <=, >, >= (relational operators)
- ==, != (equality)
- ^ (exclusive or)
- && (and)
- || (or)
- =, +=, -=,*=, /=, %= (assignment operators)
how to import java scanner to listen to input
import java.util.Scanner