Professional Documents
Culture Documents
Programming in Java
Programming in Java
Programming in Java
PROGRAMMING IN JAVA
The Math library (and more on numbers)
Primitive data types in Java
Data Type Size Description Examples of values
(1 byte = 8 bits)
byte 1 byte Whole numbers from -128 to 127 ‘A’, ‘b’, ‘1’ , ‘%’, ‘\n’
short 2 bytes Whole numbers from -32,768 to 32,767 -32,768, -10, 0, 1,
2,022, 32,767
int 4 bytes Whole numbers from -2,147,483,648 to -1,882,745, -10, 0, 1,
2,147,483,647 2,022, 32,768
long 8 bytes Whole numbers from - -1,882,745, -10, 0, 1,
9,223,372,036,854,775,808 to 2,022, 2,147,483,648
9,223,372,036,854,775,807
float 4 bytes Fractional numbers of up to 6 to 7 decimal digits 3.14159
double 8 bytes Fractional numbers of up to 15 decimal digits 3.1415926535 8979
boolean 1 bit A boolean has one of two possible values: true, false
Exercise
Write a program to generate a random whole number between 0
and N-1, with N being an integer obtained as an input argument
through the command line (i.e., the terminal window, or console).
Math.random: A practical example
Exercise 1 (5 points)
Exercise 4 (2 points)
Exercise 5 (3 points)
Exercise 6 (5 points)
Can we store irrational numbers on a computer? Why?
Exercise 7 (3 points)
Exercise 8 (7 points)
Exercise 9 (5 points)
Exercise 10 (1 point)
Exercise 11 (4 points)
Exercise 12 (5 points)
Exercise 13 (5 points)
Can we store complex numbers on a computer?