Back to all lessons


Lesson 3

Variables and if(s)

Task 0

Declare variable and assign a value. Display the variable in the next line.

Swap the lines. Try to compile and describe compiler behavior.

Task 1

Define three numerical variables: a, b, c.

Write a program that sorts it and display result i.e. "cab".

Task 2

Declare integer. Try to assign value 10.0, and try to compile.

Repair code using type convertion.

Task 3

Declare integer. Try to assign value 'b'.

Task 4

What is the difference between task 2 and task 3?

Task 5

Use "? :" operator. Show "even" or "odd" depending of user's input.

Task 6

Create an if-statement with "&&" in a condition. Then achieve the same results without ampersands.