Lesson 1
Becoming familiar with Java programming language and tools.
Objectives
- creating and running first java program
- Java lexical structures
- Java control flows
Documentation
Oracle tutorial - Lexical structures
Oracle tutorial - Language basics
Bubble sort
Notiuni introductive limbajul Java
Structuri lexicale
Citirea de la tastatura
Referinte si linkuri utile
Exercises
Exercise 1
Write a program which reads 2 numbers from console and display the maximum between them.
Exercise 2
Exercise PrintNumberInWord (nested-if, switch-case): Write a program called PrintNumberInWord which prints “ONE”, “TWO”,… , “NINE”, “OTHER” if the int variable “number” is 1, 2,… , 9, or other, respectively. Use (a) a “nested-if” statement; (b) a “switch-case” statement.
Exercise 3
Write a program which display prime numbers between A and B, where A and B are read from console. Display also how many prime numbers have been found.
Exercise 4
Giving a vector of N elements, display the maximum element in the vector.
Exercise 5
Write a program which generate a vector of 10 int elements, sort them using bubble sort method and then display the result.
Exercise 6
Being given an int number N, compute N! using 2 methods:
- a non recursive method
- a recursive method
Exercise 7
Write a “Gues the number” game in Java. Program will generate a random number and will ask user to guess it. If user guess the number program will stop. If user do not guess it program will display: 'Wrong answer, your number it too high' or 'Wrong answer, your number is too low'. Program will allow user maximum 3 retries after which will stop with message 'You lost'.