JavaLabEN#1
JavaLabEN#1
double a = 0.55;
double rez = Math.sin(a);
Random numbers
To generate random numbers, you can use either the method
double b = Math.random();
Using:
rnd.nextDouble();
rnd.nextFloat();
rnd.nextGaussian();
rnd.nextInt();
rnd.nextInt(int max);
rnd.nextLong();
In some of the tasks below, there are intervals where the function value cannot
be found. In these cases, your program must return NaN .
Double.NaN
In some cases, the function value may be so small or big that its cannot be
represented in the double. In these cases, you can see the value of -Infinity or
Infinity value.
Double.NEGATIVE_INFINITY;
Double.POSITIVE_INFINITY;
Create another one class that call main method of the class above:
Project name:
Practice1
Package name:
ua.nure.cpp.your_last_name.practice1
Class name
ua.nure.cpp.your_last_name.practice1.Part1
a5 + b, if b < 0;
a
a2 + , if 0 ≤ b ≤ 1.5;
x= a−b
a + ba + b2 , if 1.5 < b < 2.5;
3 2
4
{a , if 2.5 ≤ b.
Variable 𝑎 takes values from the range [0, 5] with a step of 0.5.
Variable 𝑏 takes values from the range [-2, 4] with a step of 0.1.
4.1, 𝑖𝑓 х > 3;
𝑦={ 𝑥3
𝑎− , if 𝑥 ≤ 3;
2
𝑎4 + b, 𝑖𝑓 𝑏 < 0;
5
2 √𝑎
𝑥= 𝑎 + ,
if 0 ≤ b ≤ 5, a ≠ b;
𝑎−b
a3 + 4a + b2 , if 5 < b < 8;
2
{𝑎5 if 8 ≤ b.
Variable 𝑎 takes values from the range [0, 5] with a step 0.5. Variable 𝑏 takes values
from the range [-3, 11] with a step 0.1.
𝑙𝑛(𝑎−𝑐)
𝑃 = 3𝑚2 − ;
b3 +a
𝑏 = 0,75 ∙ 𝑎2 + 𝑐 𝑚
𝑙𝑛(𝑡+𝑑2 )
3 , if 𝑑 > 𝑡, 𝑡 > 1;
√𝑡 2 𝑑
𝑎 = {2𝑡 𝑠𝑖𝑛( 𝑑 2), if 𝑡 > 1;
𝑡 3 𝑑, in other cases.
Variable 𝑑 takes values from the range [0, 5] with a step 1.1, variable 𝑡 takes values
from the range [0, 3] with a step 0.2; m = 3. Variable c takes a value from the
command line arguments.
The variable m takes values from the range [-5, 5] with a step 0.5; 𝑎 = 3; variable
𝑏 takes values from the range [–3, 3] with a step 1; variable с takes values from the
range [0,50] with a step 10. Variables (x, l) take values from the command line
arguments.
𝑎
2
, 𝑖𝑓 a ≠ 0 𝑎𝑛𝑑 a ≠ 𝜋;
𝑦 = {𝑙𝑛(𝑠𝑖𝑛 𝑎)
𝑐𝑜𝑠(𝑥 2 + 𝑎), 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠;
a + 𝑏 − (3.5с + √|𝑏|) a, 𝑖𝑓 𝑏 ≤ 0;
х = {𝑡𝑔 𝑏 + a , 𝑖𝑓 𝑏 > 0.5;
𝑏
3.5a𝑏, 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
The variable a takes values from the range [0, 4] with a step 0.1; the variable b
takes values from the range [2, 5] with a step 0.2. The variable c takes value from the
command line arguments.
b = 0.25a2 + с𝑚 ;
𝑙𝑛(𝑎2 −𝑑)
с = 3𝑚 − .
𝑎3 −𝑑
The variable d takes values from the range [0, 3] with a step 1; the variable t
takes values from the range [0, 4] with a step 0.5. The values of variables (с, a, m)
should be given from the command line arguments.
7. The line segments 𝑎 , b, с, 𝑑 are given. For each triple of those segments
from which a triangle can be constructed, determine and show on the screen squares of
those triangles.
8. For a triple of natural numbers, determine greatest common divisor.
9. The coordinates of the vertices of the triangle and the coordinates of the point
in it are given. Determine the distance of this point to the nearest midpoint of the side
of the triangle. (When solving the problem, take at least 3 options for the coordinates
of the vertices of the triangle and the point in it).
10. By the given value determine rest values:
3 6
√𝑎− √𝑎2 +1
𝑍= 7 .
1− √3+𝑎
𝑛
𝑦 = √𝑍 2
The 𝑎 variable takes values from the range [0, 3] with a step 1.2, the variable n
takes values from the range [10, -56] with a step 5.
25
√(𝑎 − 24)26 − 45𝑥 , 𝑖𝑓 х > 2,3;
𝑦 = { 21 2 −23
√(𝑎 − 𝑥 ) , 𝑖𝑓 х ≤ 2,3;
2
𝑎5 + 6b, 𝑖𝑓 b < 0;
45𝑎
23𝑎2 + , 𝑖𝑓 0 ≤ b ≤ 1.5, a ≠ b;
𝑥= 𝑎−b
a8 + 2ba + b8, 𝑖𝑓 1.5 < b < 2.5;
2
The variable a takes values from the range [0, 5] with a step 0.5; the variable b
takes values from the range [-2, 4] with a step 0.1. Display the results of the function
calculation:
The variable a takes values from the range [0, 5] with a step 0.5; the variable b
takes values from the range [-3, 11] with a step 0.1.
𝑏
𝑃 = √√|12 − 10𝑚| + 1 − 5𝑎 − 2𝑐 ;
𝑚+3
𝑏= √(|3𝑎 − 2| + 𝑐 )4;
(𝑝2 +5𝑝+4)𝑥
3 , 𝑖𝑓 𝑝 > 𝑥, 𝑥 > 1,
√𝑝3 𝑥 4
𝑡𝑔 𝑝 𝑥
𝑎= ( ) , 𝑖𝑓 𝑝 > 1;
𝑡𝑔 2 𝑝−1
𝑡𝑔 3 𝑥
{ , 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
6
The variable p takes values from the range [-3, 11] with a step 0.9; the variable
x takes values from the range [0, 3] with a step 0.3; m=3. The values of variables (с)
should be given from the command line arguments.
The variable m takes values from the range [-5, 5] with a step 0.5; a = 3; the
variable b takes values from the range [-3, 3] with a step 10; the variable c takes values
from the range [0, 50] with a step 10. The values of variables (x) should be given from
the command line arguments.
The variable a takes values from the range [0, 5] with a step 0.1; the variable b
takes values from the range [-2, 5] with a step 0.2. The values of variables (c) should
be given from the command line arguments.
𝜋 𝜋 3𝜋 7𝜋
b = 𝑐𝑜𝑠 𝑎 ⋅ 𝑐𝑜𝑠 2 𝑐 − 𝑠𝑖𝑛 ( + 𝑚) 𝑠𝑖𝑛 ( + 4𝑚) + 𝑠𝑖𝑛 ( + 4𝑎) 𝑐𝑜𝑠 ( − 5𝑐);
4 4 4 4
1 𝜋
с = 𝑡𝑔3 𝑎 − 1 + − 3𝑐𝑡𝑔 ( − 𝑏3 ) ⋅ 3𝑚.
𝑐𝑜𝑠 2 𝑑 2
The variable d takes values from the range [2, 15] with a step 1; the variable t
takes values from the range [0, 5] with a step 0.5; the variable m takes values from the
range [-2, 2] with a step 0.41. The values of variables (c, a) should be given from the
command line arguments.
5𝑛 1
√2⋅𝑛⋅0,54√𝑥−10 −162𝑛(√𝑥−1)
𝑦= { , 𝑍 ≠ 0;.
𝑍
0, 𝑍 = 0.
The variable x takes values from the range [0, 5] with a step 0.58; the variable n
takes values from the range [1, 5] with a step 0.5.
2 −8𝑎| 2 −8𝑎|
𝑍 = 17 ⋅ 2√|𝑎 − 8 + 2 ⋅ 4√|𝑎 .
𝑛
𝑦 = √𝑍 2
The variable a takes values from the range [0, 5] with a step 0.2; the variable n
takes values from the range [-5, 10] with a step 2.5.
4𝑥 3 − 6𝑎 + 1, 𝑖𝑓 х > 3.6;
𝑦 = { 3√5−𝑥
, 𝑖𝑓 х ≤ 3.6;
𝑎
1 1
7 (𝑎 + ) − 2 (𝑏 2 + ) , 𝑖𝑓 b < 0, a ≠ 0;
𝑏 𝑎2
8
𝑎3 − 𝑏 − |
2
, 𝑖𝑓 0 ≤ b ≤ 1;
𝑥= 𝑎3 −𝑏2 |+1
4√𝑎2 − 9𝑏 + 1, 𝑖𝑓 1 < b < 2;
7 3 7 −3 65
{ √(𝑎 − 𝑏) − √(|𝑏 − 𝑎| + 1) − 8
, 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
The variable a takes values from the range [0, 5] with a step 0.5; the variable b
takes values from the range [-2, 4] with a step 0.1.
√|12+𝑥−𝑥 2 | √|12+𝑥−𝑥 2 |
− , 𝑖𝑓 х > 12;
𝑥−11 2𝑥−9
y ={1+𝑐𝑜𝑠(2𝑥−2𝜋)+𝑐𝑜𝑠(4𝑥+2𝜋)−𝑐𝑜𝑠(6𝑥−𝜋)
2
− 2 𝑐𝑜𝑠 2 𝑥, 𝑖𝑓 𝑥 ≤ 12;
𝑐𝑜𝑠(2𝜋−2𝑥)+2 𝑐𝑜𝑠 (2𝑥+𝜋)−1
4 𝑎−𝑏 4 𝑏+𝑎
√ +√ , 𝑖𝑓 b ≠ −3, 𝑎 ≠ 4;
𝑏+3 𝑎−4
1−2 𝑐𝑜𝑠 2 2𝑎
𝜋 𝜋 , 𝑖𝑓 − 10 ≤ b < 0;
𝑥= 2𝑡𝑔(2𝑎− 4 )⋅𝑠𝑖𝑛2( 4 +2𝑏)
1 2𝑎−𝑥 𝑎+𝑏
+ − , 𝑖𝑓 b ≠ ±𝑎;
𝑎+𝑏 𝑎−𝑏 1
{√2 − 𝑎 + 4𝑏 − 3, 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
The variable a takes values from the range [0.1, 8] with a step 0.5; the variable
b takes values from the range [-3, 11] with a step 0.2.
10𝑐 𝑎
𝑏=− ;
√|2𝑚−1|+5
1
4 𝑐𝑜𝑠 𝑝 ⋅ 𝑡𝑔𝑥 − 2 𝑐𝑜𝑠 2 𝑥 − , 𝑖𝑓 𝑝 > 𝑥, 𝑥 > 1
𝑐𝑜𝑠 2 𝑝
𝑎={ 1
( 𝑡𝑔𝑥 + 𝑐𝑡𝑔𝑦) ⋅ (2 𝑠𝑖𝑛 𝑥 + 𝑡𝑔𝑦), 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
2
The variable p takes values from the range [0, 15] with a step 0.741; the variable
x takes values from the range [0, 3] with a step 0.3; m=3. The values of variables (c, y)
should be given from the command line arguments.
𝑏 2𝑎 8𝑎2
− = , 𝑖𝑓 b ≠ ±𝑎, 𝑥 ≠ ±𝑎;
𝑥−𝑎 𝑥+𝑎 𝑏2 −𝑎2
𝑡= √𝑐 2 −16 5𝑎
+ √𝑏 − 3 > , 𝑖𝑓 𝑥 ≥ 3, с ≠ ±4, 𝑏 > 5;
√𝑥−3 √𝑥−3
2
{𝑎 − 2|𝑐| − 3𝑏, 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
The variable m takes values from the range [-5, 5] with a step 0.5; a=3; the
variable x takes values from the range [-3, 3] with a step 1; the variable c takes values
from the range [0, 50] with a step 10. The values of variables (x) should be given from
the command line arguments.
3 3 6
√𝑎 + 6 − √𝑎 − 𝑏 = √𝑎2 + 𝑏2 , 𝑖𝑓 b ≤ 𝑎;
х = {√|4 − 4𝑎3 + 𝑏6 | + 6 + 𝑎 − 3√2, 𝑖𝑓 b > 0.5;
3 3 3 3 3 3
(𝑎 √𝑎 − 2𝑎 √𝑏 + √𝑎2 𝑏2 + √𝑎2 𝑏 − √𝑎𝑏2 ) ÷ √𝑎2 + 1, 𝑖𝑛 𝑜𝑡ℎ𝑒𝑟 𝑐𝑎𝑠𝑒𝑠.
The variable a takes values from the range [0, 5] with a step 0.1; the variable b
takes values from the range [-2, 5] with a step 0.2.
𝑐 2 +1 𝑚
b= + − 2.9𝑎;
2 √𝑎2 +1
The variable d takes values from the range [-5, 5] with a step 1; the variable t
takes values from the range [0, 5] with a step 0.5; the variable m takes values from the
range [-2, 5] with a step 0.41.
1 1 𝑎+1
𝑍=( + ) ÷ (1 + √ ),
√𝑎+√𝑎+1 √𝑎+√𝑎+1 𝑎−1
𝑍 2 +𝑛 𝑛2 −𝑍+2
𝑦=| − .
𝑍 2 −𝑛+1|+3 |𝑛2 −𝑍−2|+2
The variable a takes values from the range [3, 15] with a step 0.58; the variable
n takes values from the range [1, 5] with a step 0.5.
Class name
ua.nure.cpp.your_last_name.practice1.Part2
Forbidden package:
java.util.*
[1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
[13, 14, 15, 16]
1. For the given matrix (N+15)x(N+15) sort the main diagonal in ascending
order by moving rows or columns { отсортировать главную диагональ }. Generate
numbers randomly in the interval [-N-15; N+15]
2. For the given matrix (N+15)x(N+15) sort the even rows in ascending order,
and sort odd rows in descending order { отсортировать четные строки в прямом
порядке, а нечетные в обратном }. Generate numbers randomly in the interval [-N-
15; N+15]
3. For the given matrix (N+15)x(N+15) sort columns in descending order of sum
of numbers in columns { отсортировать столбцы по убыванию суммы чисел в
столбцах }. Generate numbers randomly in the interval [-N-15; N+15]
4. For the given matrix (N+15)x(N+15) sort elements on even rows only
{ отсортировать элементы только четных строках }. Generate numbers randomly
in the interval [-N-15; N+15]
5. For the given vector (N+15) sort even numbers in ascending order (odd
numbers should stay on their places) { отсортировать четные числа по возрастанию
(нечетные оставить на своих местах) }. Generate numbers randomly in the interval
[-N-15; N+15]
6. For the given matrix (N+15)x(N+15) sort each even column in ascending
order { отсортировать каждый четный столбец }. Generate numbers randomly in the
interval [-N-15; N+15]
7. For the given matrix (N+15)x(N+15) sort each even column in descending
order separately and each odd column in ascending order separately { отсортировать
четные столбцы в обратном порядке, а нечетные в прямом }. Generate numbers
randomly in the interval [-N-15; N+15]
8. For the given matrix (N+15)x(N+15) sort rows in ascending order of sum of
numbers in rows { отсортировать строки по возрастанию суммы чисел в этих
строках }. Generate numbers randomly in the interval [-N-15; N+15]
9. For the given matrix (N+15)x(N+15) sort each odd column in ascending order
{ отсортировать каждый нечетный столбец }. Generate numbers randomly in the
interval [-N-15; N+15]
10. For the given matrix (N+15)x(N+15) sort odd rows in ascending order
{ отсортировать нечетные строки }. Generate numbers randomly in the interval [-N-
15; N+15]
11. For the given vector (N+15) sort each even column in ascending order
{ отсортировать нечетные числа по убыванию (четные оставить на своих
местах) }. Generate numbers randomly in the interval [-N-15; N+15]
12. For the given matrix (N+15)x(N+15) determine the sum of numbers above
main diagonal and compare it with the sum of numbers below main diagonal (ignore
main diagonal). If the sum of top elements greater than the sum of bottom elements,
sort matrix in descending order otherwise sort matrix in ascending order { найти
сумму всех чисел стоящих выше главной диагонали и сравнить ее с суммой чисел
стоящих ниже (главную диагональ не учитывать). Если сумма верхних больше
суммы нижних, тогда отсортировать всю матрицу по убыванию, иначе по
возрастанию }. Generate numbers randomly in the interval [-N-15; N+15]
13. For the given matrix (N+15)x(N+15) { если сумма всех чисел в строках
больше суммы всех чисел в столбцах, тогда зеркально отобразить матрицу
относительно побочной диагонали, иначе отсортировать по возрастанию }.
Generate numbers randomly in the interval [-N-15; N+15]
14. For the given matrix (N+15)x(N+15) sort it in ascending order and write the
result in the form of a horizontal descending snake { отсортировать по возрастанию
и записать результат в виде горизонтальной нисходящей змейки }. Generate
numbers randomly in the interval [-N-15; N+15]
1 2 3
6 5 4
7 8 9
12 11 10
10 3 2
9 4 1
8 5 0
7 6 -1
17. For the given matrix (N+15)x(N+15) if the sum of even numbers greater
than the sum of odd numbers, sort the matrix in ascending order otherwise in
descending order { если сумма четных чисел больше суммы нечетных, тогда
сортировать по возрастанию, иначе по убыванию }. Generate numbers randomly in
the interval [-N-15; N+15]
18. For the given matrix (N+15)x(N+15) find rows that contain maximum and
minimum elements and swap them. If rows match, zero them { найти строки с
максимальным и минимальным элементом и поменять их местами, если строки
совпадают, обнулить их }. Generate numbers randomly in the interval [-N-15; N+15]
19. For the given matrix (N+15)x(N+15) find the minimum element and subtract
its value from the surrounding elements. The matri { найти минимальный элемент и
вычесть его величину из окружающих его элементов. Матрицу рассматривать
как замкнутое пространство }. Generate numbers randomly in the interval [-N-15;
N+15]
20. For the given matrix (N*10+1)x(N*10+1) { отсортировать главную и
побочную диагонали, если стоящий в точке пересечения элемент совпадает,
тогда вернуть матрице исходный вид и отсортировать в прямом порядке все
четные столбцы, иначе отсортировать в обратном порядке все нечетные строки }.
Generate numbers randomly in the interval [-N-15; N+15]
21. For the given matrix (N+15)x(N+15) sort odd elements in ascending order
in the each even row, even element fill zero { отсортировать нечетные элементы в
каждой четной строке, все четные элементы обнулить }. Generate numbers
randomly in the interval [-N-15; N+15]
22. For the given matrix (2*N+5)x(2*N+5) sort each odd row, write the sum of
the elements of the previous odd row into each element of the even line
{ отсортировать каждую нечетную строку в каждый элемент четной строки
записать сумму элементов предыдущей нечетной строки }. Generate numbers
randomly in the interval [-N-15; N+15]
23. For the given matrix (N+15)x(N+15) find the sum of the matrix element.
Find the maximum element and fill zeros all elements in its row and column. Re-find
the sum of all the numbers in the matrix. If the sum of the original is greater, return the
matrix to its original form and sort all even rows, otherwise leave the matrix in the
transformed form { найти сумму всех чисел матрицы. Найти максимальный
элемент матрицы и обнулить все элементы, которые находятся в
соответствующем столбце и строке. Повторно найти сумму всех чисел матрицы.
Если сумма исходной больше, вернуть матрице исходный вид и отсортировать
все четные строки, иначе оставить матрицу в преобразованном виде }. Generate
numbers randomly in the interval [-N-15; N+15]
24. For the given matrix (N+15)x(N+15) find the sum of all the numbers in the
matrix. Find the smallest element and add its absolute value to each element of the
matrix. Calculate the sum of squares for both matrices { найти сумму всех чисел
матрицы. Найти минимальный элемент и прибавить его абсолютное значение к
каждому элементу матрицы. Рассчитать сумму квадратов для обеих матриц }.
Generate numbers randomly in the interval [-N-15; N+15]
25. For the given matrix (N+15)x(N+15) find the sum of the numbers in even
columns. Sort and re-find the sum, if the first sum is greater, return the original form
of the matrix and zero every odd row, if the second sum is larger, zero every even row,
leaving the matrix sorted { найти сумму чисел стоящих в четных столбцах.
Отсортировать и повторно найти сумму, если первая сумма будет больше,
вернуть исходный вид матрицы и обнулить каждую нечетную строку, если
вторая сумма окажется больше обнулить каждую четную строку, оставив
матрицу отсортированной }. Generate numbers randomly in the interval [-N-15;
N+15]
1.4 Questions
1. What parts does a Java program consist of? { Из каких частей состоит Java
- программа? }
2. What are the main types of variables in the Java language? { Назовите
основные типы переменных языка Java. }
3. What types of variables are basic? { Какие типы переменных являются
базовыми? }
4. Provide the characteristic of integer data types: int, char, short, long, byte.
{ Предоставьте характеристику целочисленных типов данных: int, char, short,
long. }
5. Provide a characteristic of floating point data types: float, double.
{ Предоставьте характеристику действительных типов данных: float, double. }
6. What are expressions in Java? { Что такое выражения в языке Java? }
7. What are the arithmetic operations that are used in the Java language?
{ Назовите арифметические операции, которые используются в языке Java? }
8. What are increment and decrement operations? Their forms. { Что такое
операции увеличения и уменьшения? Их формы. }
9. What are "increase by", "decrease by" operations? Their kind. { Что такое
операции "увеличение на", "уменьшение на"? Их разновидность. }
10. Which bitwise operations are used in Java? { Которые побитовые
операции используются в языке Java? }
11. What are the shift operations used in Java? { Какие операции смещения
используются в языке Java? }
12. Give a characteristic to the Java language flow control statements: if-else,
while, for. { Предоставьте характеристику управляющим конструкциям языка
Java: if-else, while, for. }
13. What are the main features of the Eclipse tool? { Назовите основные
возможности инструментального средства Eclipse. }