Exercises¶
Below are a list of exercises to complete. Answers will be provided in the next section.
Important
To learn properly it is recommended to attempt the exercises before looking at the answers.
Write a program that displays each data type. An example output is shown.
byte: 125
short: 32000
int: 500000
long: 9999999999
float: 10.4
double: -50112.56
char: A
boolean: true
Write a program that changes the value of a variable 3 times. An example output is shown.
Original: 105
Change 1: 110
Change 2: -15
Change 3: 12
Add the following variables together.
int x = 10;
int y = 12;
int z = 42;
Example output
10 + 12 + 42 = 64
Challenge Question¶
Note
Challenge questions are here to stump you and test your problem solving skills. The content in a challenge question will be covered in later units.
Create a Pythagorean calculator. The user will input values for
a
andb
. The calculator should respond with the length of the hypotenuse.
The formula for Pythagorean theorem is: \(a^2 + b^2 = c^2\)
Example
Welcome to the Pythagorean Calculator!!!
Enter the length of side A: 3
Enter the length of side B: 4
Calculating
The length of the hypotenuse is: 5