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

Read a number from standard input and assign the value to a variable. Here comes a hint:


java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println(sc.nextInt());                
            
Task 2

Write a program, that reads two numbers and displays sum of them.

Task 3

Write a program, that reads two numbers and divide them safely.

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,∞)