Back to all lessons


Lesson 2

Variables and if(s)

Task 0

Create variables for all known types and initialize them with values.

Task 1

Try to assign a float value to: integer, char and boolean.

Then try to assign a char value to: double, integer and boolean

Comment incorrect assignments.

Task 2

Try to cast values in Task 1, if it is possible.

Task 3

Write a program with two numerical variables. Display: a sum, difference, multiplication and division.

Make sure program will work with any possible values assigned to variables.

Task 4

Use bitwise operations to check, if a number is odd or even.

Task 5

Write a program, that classifies a given number to one or more ranges:

  • X=[-1,1]
  • Y=[-∞,2)
  • Z=(-2,∞)