├── Lesson-10.java ├── Lesson-11.java ├── Lesson-3.java ├── Lesson-36.sql ├── Lesson-37.sql ├── Lesson-38.sql ├── Lesson-39.sql ├── Lesson-4.java ├── Lesson-40.sql ├── Lesson-5.java ├── Lesson-6.java ├── Lesson-9.java └── README.md /Lesson-10.java: -------------------------------------------------------------------------------- 1 | // Queue 2 | https://codeboard.io/projects/343946 3 | 4 | // ArrayList #1 5 | 6 | import java.util.*; 7 | import java.util.ArrayList; 8 | 9 | public class Main { 10 | 11 | public static void print(ArrayList list) { 12 | for(int i = 0; i < list.size(); i++) { 13 | System.out.print(list.get(i) + " "); 14 | } 15 | System.out.println(); 16 | } 17 | 18 | public static void setByName(ArrayList list, String name1, String name2) { 19 | 20 | if(list.contains(name1) == true) { 21 | int index = list.indexOf(name1); 22 | list.set(index, name2); 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | 28 | ArrayList list = new ArrayList(); 29 | list.add("Kate"); 30 | print(list); 31 | 32 | list.add("Anton"); 33 | print(list); 34 | 35 | list.add("Sergey"); 36 | print(list); 37 | 38 | list.add(1, "Anna"); 39 | print(list); 40 | 41 | list.set(2, "Denis"); 42 | print(list); 43 | 44 | setByName(list, "Sergey", "Veronika"); 45 | print(list); 46 | 47 | setByName(list, "Ivan", "Vasilii"); 48 | print(list); 49 | 50 | list.add("Sergey"); 51 | list.add("Viktoria"); 52 | list.add("Ivan"); 53 | print(list); 54 | 55 | list.remove(5); 56 | print(list); 57 | 58 | list.add("Anna"); 59 | print(list); 60 | list.remove("Anna"); 61 | print(list); 62 | 63 | } 64 | } 65 | 66 | // ArrayList #2 67 | https://codeboard.io/projects/343959 -------------------------------------------------------------------------------- /Lesson-11.java: -------------------------------------------------------------------------------- 1 | // Exceptions 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | 8 | System.out.println("Hello, World!"); 9 | 10 | int a = 10; 11 | int b = 0; 12 | int c = a / b; 13 | 14 | System.out.println(c); 15 | } 16 | } 17 | 18 | import java.util.*; 19 | 20 | public class Main { 21 | public static void main(String[] args) { 22 | 23 | try { 24 | int a = 10; 25 | int b = 0; 26 | System.out.println(a/b); 27 | } 28 | catch(Exception e) { 29 | System.out.println("Делить на ноль нельзя!"); 30 | } 31 | } 32 | } 33 | 34 | import java.util.*; 35 | 36 | public class Main { 37 | public static void main(String[] args) { 38 | 39 | int a = 10; 40 | int b = 0; 41 | int[] array = new int[10]; 42 | 43 | try { 44 | int c = a / b; 45 | array[5] = 10; 46 | } 47 | catch(ArithmeticException ae) { 48 | System.out.println("Делить на ноль нельзя!"); 49 | } 50 | catch(ArrayIndexOutOfBoundsException ai) { 51 | System.out.println("Ой! Вышли за границу массива!"); 52 | } 53 | catch(Exception e) { 54 | System.out.println("Что-то пошло не так..."); 55 | } 56 | 57 | System.out.println("Я живая!!!"); 58 | } 59 | } 60 | 61 | // StackTrace 62 | 63 | import java.util.*; 64 | 65 | public class Main { 66 | 67 | public static void method1() { 68 | method2(); 69 | } 70 | 71 | public static void method2() { 72 | method3(); 73 | } 74 | 75 | public static void method3() { 76 | int a = 10; 77 | int b = 0; 78 | int c = a / b; 79 | method4(); 80 | } 81 | public static void method4() { 82 | method5(); 83 | } 84 | public static void method5() { 85 | System.out.println("Hello, World!"); 86 | } 87 | 88 | public static void main(String[] args) { 89 | method1(); 90 | } 91 | } 92 | 93 | import java.util.*; 94 | 95 | public class Main { 96 | public static void main(String[] args) { 97 | 98 | int a = 10; 99 | int b = 0; 100 | int[] array = new int[10]; 101 | 102 | try { 103 | int c = a / b; 104 | array[5] = 10; 105 | } 106 | catch(ArithmeticException ae) { 107 | System.out.println("Делить на ноль нельзя!"); 108 | ae.printStackTrace(); 109 | } 110 | catch(ArrayIndexOutOfBoundsException ai) { 111 | System.out.println("Ой! Вышли за границу массива!"); 112 | } 113 | catch(Exception e) { 114 | System.out.println("Что-то пошло не так..."); 115 | } 116 | 117 | System.out.println("Я живая!!!"); 118 | } 119 | } 120 | 121 | import java.util.*; 122 | import java.util.Random; 123 | 124 | public class Main { 125 | public static void main(String[] args) { 126 | 127 | int[] array = new int[10]; 128 | Random r = new Random(); 129 | 130 | try { 131 | for(int i = 0; i <= 10; i++) { 132 | array[i] = r.nextInt(100); 133 | } 134 | } 135 | catch(ArrayIndexOutOfBoundsException e) { 136 | System.out.println("Границ не видим!!!"); 137 | } 138 | 139 | try { 140 | for(int i = 0; i <= array.length; i++) { 141 | System.out.print(array[i] + " "); 142 | } 143 | } 144 | catch(ArrayIndexOutOfBoundsException ex) { 145 | System.out.println("Опять?!"); 146 | } 147 | } 148 | } 149 | 150 | // Unit tests 151 | https://codeboard.io/projects/344221 152 | https://codeboard.io/projects/344225 -------------------------------------------------------------------------------- /Lesson-3.java: -------------------------------------------------------------------------------- 1 | // Объявление переменной 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | 8 | int x; 9 | x = 10; 10 | 11 | System.out.println(x); 12 | 13 | x = 15; 14 | System.out.println(x); 15 | 16 | x = -25; 17 | System.out.println(x); 18 | } 19 | } 20 | 21 | import java.util.*; 22 | 23 | public class Main { 24 | public static void main(String[] args) { 25 | 26 | int x = 100; 27 | System.out.println(x); 28 | } 29 | } 30 | 31 | import java.util.*; 32 | 33 | public class Main { 34 | public static void main(String[] args) { 35 | 36 | double y = 100.12352; 37 | 38 | System.out.println(y); 39 | } 40 | } 41 | 42 | import java.util.*; 43 | 44 | public class Main { 45 | public static void main(String[] args) { 46 | 47 | String s = "Hello World!"; 48 | 49 | System.out.println(s); 50 | } 51 | } 52 | 53 | import java.util.*; 54 | 55 | public class Main { 56 | public static void main(String[] args) { 57 | 58 | boolean s = false; 59 | 60 | System.out.println(s); 61 | } 62 | } 63 | 64 | // Статическая типизация 65 | import java.util.*; 66 | 67 | public class Main { 68 | public static void main(String[] args) { 69 | 70 | int a = 50; 71 | 72 | a = "Some text"; 73 | } 74 | } 75 | 76 | // Динамическая типизация (на PHP) 77 | 91 | 92 | // Арифметика 93 | import java.util.*; 94 | 95 | public class Main { 96 | public static void main(String[] args) { 97 | 98 | int a = 50; 99 | int b = 8; 100 | 101 | int result1 = a + b; 102 | System.out.println(result1); 103 | 104 | int result2 = a * b; 105 | System.out.println(result2); 106 | 107 | int result3 = a - b; 108 | System.out.println(result3); 109 | 110 | // Целочисленное деление 111 | int result4 = a / b; 112 | System.out.println(result4); 113 | 114 | // Получение остатка 115 | int result5 = a % b; 116 | System.out.println(result5); 117 | } 118 | } 119 | 120 | // Арифметика 121 | import java.util.*; 122 | 123 | public class Main { 124 | public static void main(String[] args) { 125 | 126 | double a = 20; 127 | double b = 3; 128 | 129 | double result1 = a + b; 130 | System.out.println(result1); 131 | 132 | double result2 = a * b; 133 | System.out.println(result2); 134 | 135 | double result3 = a - b; 136 | System.out.println(result3); 137 | 138 | // Целочисленное деление 139 | double result4 = a / b; 140 | System.out.println(result4); 141 | 142 | // Получение остатка 143 | double result5 = a % b; 144 | System.out.println(result5); 145 | } 146 | } 147 | 148 | 149 | // Приведение типов 150 | import java.util.*; 151 | 152 | public class Main { 153 | public static void main(String[] args) { 154 | 155 | byte a = 100; 156 | int b = 5; 157 | 158 | System.out.println(a); 159 | System.out.println(b); 160 | 161 | int result = a + b; 162 | System.out.println(result); 163 | } 164 | } 165 | 166 | // Деление на 0 (целое) 167 | import java.util.*; 168 | 169 | public class Main { 170 | public static void main(String[] args) { 171 | 172 | int a = 50; 173 | int b = 0; 174 | 175 | int result = a / b; 176 | 177 | System.out.println(result); 178 | } 179 | } 180 | 181 | // Деление на 0 (вещественное) 182 | import java.util.*; 183 | 184 | public class Main { 185 | public static void main(String[] args) { 186 | 187 | double a = 50; 188 | double b = 0; 189 | 190 | double result = a / b; 191 | 192 | System.out.println(result); 193 | } 194 | } 195 | 196 | // Инкремент и декремент 197 | import java.util.*; 198 | 199 | public class Main { 200 | public static void main(String[] args) { 201 | 202 | int a = 10; 203 | System.out.println(a); 204 | 205 | a = a + 1; 206 | System.out.println(a); 207 | 208 | a++; 209 | System.out.println(a); 210 | 211 | a--; 212 | System.out.println(a); 213 | } 214 | } 215 | 216 | // Инкремент и декремент 217 | import java.util.*; 218 | 219 | public class Main { 220 | public static void main(String[] args) { 221 | 222 | int a = 10; 223 | System.out.println(a); 224 | 225 | a = a + 1; 226 | System.out.println(a); 227 | 228 | a++; 229 | System.out.println(a); 230 | 231 | a--; 232 | System.out.println(a); 233 | } 234 | } 235 | 236 | // Приоритет операций 237 | import java.util.*; 238 | 239 | public class Main { 240 | public static void main(String[] args) { 241 | 242 | int result = 3 * (10 / 5 - 3 * (5 - 2)); 243 | 244 | System.out.println(result); 245 | } 246 | } 247 | 248 | -------------------------------------------------------------------------------- /Lesson-36.sql: -------------------------------------------------------------------------------- 1 | -- Создание таблицы 2 | 3 | CREATE TABLE Phones 4 | ( 5 | id INTEGER, 6 | manufacturer VARCHAR(20) NOT NULL, 7 | model VARCHAR(20) NOT NULL, 8 | price INTEGER NOT NULL, 9 | quantity INTEGER NOT NULL DEFAULT 0, 10 | PRIMARY KEY (id) 11 | ) 12 | 13 | -- Заполнение таблицы 14 | 15 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (1, 'Apple', 'iPhone 10XXL',99000, 17); 16 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (2, 'Apple', 'iPhone 10L',80000, 6); 17 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (15, 'Apple', 'iPhone 9',65000, 16); 18 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (18, 'Apple', 'iPhone 10',75000, 3); 19 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (21, 'Apple', 'iPhone 12 ProMaxXL',120000, 17); 20 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (22, 'Apple', 'iPhone 10',89000, 11); 21 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (24, 'Apple', 'iPhone 11',105000, 11); 22 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (8, 'LG', 'D201',55000, 0); 23 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (17, 'LG', 'D201X',75000, 15); 24 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (10, 'Motorola', 'E398',34000, 3); 25 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (12, 'Motorola', 'E398',34000, 15); 26 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (14, 'Motorola', 'E398',38000, 3); 27 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (19, 'Motorola', 'E398',38000, 9); 28 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (23, 'Motorola', 'RZR V3',44000, 15); 29 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (27, 'Motorola', 'RZR V10',55000, 9); 30 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (3, 'Samsung', 'A110',30000, 6); 31 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (5, 'Samsung', 'Galaxy XL',80000, 8); 32 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (6, 'Samsung', 'Galaxy Big',140000, 19); 33 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (7, 'Samsung', 'A320',50000, 11); 34 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (13, 'Samsung', 'A100',35000, 10); 35 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (16, 'Samsung', 'Note 100',90000, 3); 36 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (26, 'Samsung', 'Note 100',100000, 17); 37 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (4, 'Xiaomi', 'EP100',25000, 18); 38 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (9, 'Xiaomi', 'EP100',30000, 18); 39 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (11, 'Xiaomi', 'EP200',45000, 2); 40 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (20, 'Xiaomi', 'EP300',55000, 13); 41 | INSERT INTO Phones(id,manufacturer, model,price,quantity) VALUES (25, 'Xiaomi', 'EP300XL',65000, 4); 42 | 43 | INSERT INTO Phones(id,manufacturer, model,price) VALUES (102, 'Apple', 'iPhone 10XXL',99000); 44 | 45 | -- Вывести всю таблицу 46 | SELECT * FROM phones 47 | 48 | -- Вывести некоторые столбцы таблицу 49 | SELECT manufacturer, model, price FROM phones 50 | 51 | SELECT *, price * quantity AS total FROM phones 52 | 53 | -- Сортировка 54 | SELECT * FROM phones 55 | ORDER BY price 56 | DESC 57 | LIMIT 5 58 | 59 | -- Фильтрация 60 | SELECT * FROM phones WHERE manufacturer = 'Samsung' 61 | 62 | SELECT * FROM phones WHERE price = 100000 63 | 64 | SELECT * FROM phones WHERE price >= 100000 65 | 66 | SELECT * FROM phones WHERE price >= 100000 AND manufacturer = 'Samsung' AND quantity > 18 67 | 68 | -- Вывести телефоны ценой 50к-100к 69 | SELECT * FROM phones WHERE price >= 50000 AND price <= 100000 70 | SELECT * FROM phones WHERE price BETWEEN 50000 AND 100000 71 | 72 | -- Вывести все телефоны, отличные от Apple 73 | SELECT * FROM phones WHERE manufacturer != 'Apple' 74 | 75 | -- Вывести все телефоны Apple и Samsung 76 | SELECT * FROM phones WHERE manufacturer IN ('Apple', 'Samsung') 77 | 78 | -- Вывести все телефоны, отличные от Apple и Samsung 79 | SELECT * FROM phones WHERE manufacturer NOT IN ('Apple', 'Samsung') 80 | 81 | -- Фильтрация + сортировка 82 | SELECT * FROM phones WHERE price > 30000 AND quantity > 5 83 | ORDER BY price 84 | DESC 85 | LIMIT 7 86 | 87 | -- Каких моделей на остатке меньше трех штук 88 | SELECT * FROM phones WHERE quantity < 3 89 | 90 | -- Вывести список производителей телефонов 91 | SELECT DISTINCT(manufacturer) manufacturer FROM phones 92 | 93 | 94 | -- Обновление данных 95 | UPDATE phones 96 | SET price = 55000 97 | WHERE id = 5 98 | 99 | 100 | -- А можно, например, массово изменить прайс +10%, у всех кто >40тыс 101 | UPDATE phones 102 | SET price = price * 1.1 103 | WHERE price > 40000 104 | 105 | -------------------------------------------------------------------------------- /Lesson-37.sql: -------------------------------------------------------------------------------- 1 | -- Вывести максимальное значение цены 2 | SELECT price FROM phones 3 | ORDER BY price 4 | DESC 5 | LIMIT 1 6 | 7 | SELECT MAX(price) FROM phones 8 | 9 | -- Агрегатные функции 10 | SELECT MAX(price) FROM phones 11 | SELECT MIN(price) FROM phones 12 | SELECT AVG(price) FROM phones 13 | SELECT SUM(price) FROM phones 14 | SELECT COUNT(price) FROM phones 15 | 16 | SELECT MIN(manufacturer) FROM phones 17 | 18 | SELECT MIN(price), MAX(price), AVG(price), SUM(price), COUNT(price) FROM phones 19 | 20 | -- Найти "истинное" среднее значение цены 21 | SELECT SUM(price * quantity)/SUM(quantity) FROM phones 22 | 23 | -- Вывести информацию о самом дорогом телефоне 24 | SELECT * FROM phones 25 | ORDER BY price 26 | DESC 27 | LIMIT 1 28 | 29 | -- Вывести информацию о самом дорогом телефоне 30 | SELECT * FROM phones WHERE price = (SELECT MAX(price) FROM phones) 31 | 32 | -- Вывести информацию о телефонах с ценой, выше среденей 33 | SELECT * FROM phones WHERE price > (SELECT SUM(price * quantity) / SUM(quantity) FROM phones) 34 | 35 | -- Вывести информацию о телефонах с ценой, выше среденей, и с количеством меньше среднего 36 | SELECT * FROM phones 37 | WHERE 38 | price > (SELECT SUM(price * quantity) / SUM(quantity) FROM phones) 39 | AND 40 | quantity < (SELECT AVG(quantity) FROM phones) 41 | 42 | -- Вывести количество уникальных производителей 43 | SELECT COUNT(DISTINCT(manufacturer)) FROM phones 44 | 45 | -- Вывести производителей и среднюю цену за их продукцию 46 | SELECT manufacturer, AVG(price) FROM phones 47 | GROUP BY manufacturer 48 | 49 | -- 50 | SELECT manufacturer, model, AVG(price), MIN(price), SUM(quantity) FROM phones 51 | GROUP BY manufacturer, model 52 | 53 | -- когда нужно вывести телефоны с одинаковой ценой 54 | SELECT price, COUNT(model) FROM phones 55 | GROUP BY price 56 | HAVING COUNT(price) > 1 57 | 58 | -- Вывести производителей и среднюю цену за их продукцию, которая больше 50000 59 | SELECT manufacturer, ROUND(AVG(price), 0) FROM phones 60 | GROUP BY manufacturer 61 | HAVING AVG(price) > 50000 62 | 63 | -- Вывести производителей и среднюю цену за их продукцию, которая больше 50000 64 | SELECT manufacturer, ROUND(SUM(price * quantity) / SUM(quantity), 0) FROM phones WHERE quantity > 0 65 | GROUP BY manufacturer 66 | HAVING (SUM(price * quantity) / SUM(quantity))> 50000 -------------------------------------------------------------------------------- /Lesson-38.sql: -------------------------------------------------------------------------------- 1 | -- Вывести всю информацию 2 | SELECT * FROM products 3 | JOIN manufacturers ON manufacturers.id = products.manufacturer_id 4 | JOIN prices ON prices.product_id = products.id 5 | 6 | 7 | -- Вывести всю информацию 8 | SELECT pr.name, mn.name, mn.location, pc.value, pc.discount FROM products pr 9 | JOIN manufacturers mn ON mn.id = pr.manufacturer_id 10 | JOIN prices pc ON pc.product_id = pr.id 11 | 12 | -- RIGHT/LEFT JOIN 13 | SELECT pr.name, mn.name, mn.location FROM manufacturers mn LEFT JOIN products pr ON mn.id = pr.manufacturer_id 14 | 15 | SELECT pr.name, mn.name, mn.location FROM products pr RIGHT JOIN manufacturers mn ON mn.id = pr.manufacturer_id 16 | 17 | SELECT pr.name, pc.value, pc.discount FROM products pr LEFT JOIN prices pc ON pc.product_id = pr.id 18 | 19 | -- Вывести все неполные данные 20 | SELECT pr.name, mn.name, mn.location, pc.value, pc.discount FROM products pr 21 | RIGHT JOIN manufacturers mn ON mn.id = pr.manufacturer_id 22 | LEFT JOIN prices pc ON pc.product_id = pr.id 23 | WHERE pr.name IS null OR pc.value IS null 24 | 25 | -- Вывести все товары из Москвы с ценой больше 4000 26 | SELECT pr.name, mn.name, mn.location, pc.value, pc.discount FROM products pr 27 | JOIN manufacturers mn ON mn.id = pr.manufacturer_id 28 | JOIN prices pc ON pc.product_id = pr.id 29 | WHERE mn.location = 'Moscow' AND pc.value > 4000 30 | 31 | -- Вывести все товары из Москвы с ценой больше 4000 32 | SELECT pr.name, mn.name, mn.location, pc.value, pc.discount FROM products pr 33 | JOIN manufacturers mn ON mn.id = pr.manufacturer_id AND mn.location = 'Moscow' 34 | JOIN prices pc ON pc.product_id = pr.id AND pc.value > 4000 35 | 36 | -- Вывести производителя и среднюю цену на его товары (средняя цена > 8000) 37 | SELECT mn.name, ROUND(AVG(pc.value), 0) FROM products pr 38 | JOIN manufacturers mn ON mn.id = pr.manufacturer_id 39 | JOIN prices pc ON pc.product_id = pr.id 40 | GROUP BY mn.name 41 | HAVING AVG(pc.value) > 8000 42 | ORDER BY AVG(pc.value) 43 | DESC 44 | 45 | 46 | -- Вывести информацию о самом дорогом товаре 47 | SELECT pr.name, mn.name, mn.location, pc.value, pc.discount FROM products pr 48 | JOIN manufacturers mn ON mn.id = pr.manufacturer_id 49 | JOIN prices pc ON pc.product_id = pr.id 50 | WHERE pc.value = (SELECT MAX(prc.value) FROM prices prc) 51 | 52 | -------------------------------------------------------------------------------- /Lesson-39.sql: -------------------------------------------------------------------------------- 1 | SELECT mn.name, m.name, m.inStock, q.count, p.value, p.max_discount FROM models m 2 | JOIN sellers s ON s.id = m.seller_id 3 | JOIN offices o ON o.id = s.office_id 4 | JOIN quantity q ON q.model_id = m.id 5 | JOIN prices p ON p.id = m.price_id 6 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 7 | JOIN countries c ON c.id = mn.country_id 8 | JOIN regions r ON r.id = c.region_id 9 | 10 | 11 | -- Найти страну с максимальной капитализацией всех её производителей 12 | SELECT c.name, SUM(mn.capitalization) FROM manufacturers mn 13 | JOIN countries c ON c.id = mn.country_id 14 | GROUP BY c.name 15 | ORDER BY SUM(mn.capitalization) 16 | DESC 17 | LIMIT 1 18 | 19 | 20 | -- Найти страну с максимальной капитализацией всех её производителей 21 | SELECT c.name, SUM(mn.capitalization) FROM manufacturers mn 22 | JOIN countries c ON c.id = mn.country_id 23 | GROUP BY c.name 24 | HAVING SUM(mn.capitalization) = 25 | (SELECT SUM(manufacturers.capitalization) FROM manufacturers 26 | JOIN countries ON countries.id = manufacturers.country_id 27 | GROUP BY countries.name 28 | ORDER BY SUM(manufacturers.capitalization) 29 | DESC 30 | LIMIT 1) 31 | 32 | 33 | -- Вывести всю доступную информацию о моделе: имя производителя, имя модели, цена, остаток, страна производства 34 | SELECT mn.name, m.name, p.value, q.count, c.name FROM models m 35 | JOIN quantity q ON q.model_id = m.id 36 | JOIN prices p ON p.id = m.price_id 37 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 38 | JOIN countries c ON c.id = mn.country_id 39 | 40 | 41 | -- Вывести все автомобили и их продавцов, которыми занимаются сотрудники офиса ‘Laconia’ 42 | SELECT m.name, s.first_name, s.last_name, o.name FROM models m 43 | JOIN sellers s ON s.id = m.seller_id 44 | JOIN offices o ON o.id = s.office_id 45 | WHERE o.id = (SELECT id FROM offices WHERE name = 'Laconia') 46 | 47 | 48 | -- Найти марку с наибольшим количеством автомобилей в системе 49 | 50 | SELECT mn.name, SUM(q.count) FROM models m 51 | JOIN quantity q ON q.model_id = m.id 52 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 53 | GROUP BY mn.name 54 | HAVING SUM(q.count) = 55 | (SELECT SUM(quantity.count) FROM models 56 | JOIN quantity ON quantity.model_id = models.id 57 | JOIN manufacturers ON manufacturers.id = models.manufacturer_id 58 | GROUP BY manufacturers.name 59 | ORDER BY SUM(quantity.count) 60 | DESC 61 | LIMIT 1) 62 | 63 | 64 | -- Найти все модели, что может купить потребитель 65 | 66 | SELECT mn.name, m.name, m.inStock, q.count FROM models m 67 | JOIN quantity q ON q.model_id = m.id 68 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 69 | WHERE m.inStock = true AND q.count > 0 70 | 71 | 72 | -- Вывести среднее значение цены всех доступных к продаже автомобилей 73 | 74 | SELECT AVG(p.value) FROM models m 75 | JOIN quantity q ON q.model_id = m.id 76 | JOIN prices p ON p.id = m.price_id 77 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 78 | WHERE m.inStock = true AND q.count > 0 79 | 80 | 81 | -- Вывести среднее значение цены всех доступных к продаже автомобилей 82 | 83 | SELECT SUM(p.value * q.count) / SUM(q.count) FROM models m 84 | JOIN quantity q ON q.model_id = m.id 85 | JOIN prices p ON p.id = m.price_id 86 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 87 | WHERE m.inStock = true AND q.count > 0 88 | 89 | 90 | -- Вывести общую стоимость всех автомобилей марки ‘Horch’ 91 | 92 | SELECT SUM(q.count * p.value) FROM models m 93 | JOIN quantity q ON q.model_id = m.id 94 | JOIN prices p ON p.id = m.price_id 95 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 96 | WHERE mn.name = 'Horch' AND q.count > 0 97 | 98 | 99 | -- Вывести все модели, которые продает самый востребованный продавец 100 | 101 | SELECT mn.name, m.name FROM models m 102 | JOIN sellers s ON s.id = m.seller_id 103 | JOIN quantity q ON q.model_id = m.id 104 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 105 | WHERE s.id = 106 | (SELECT s.id FROM models m 107 | JOIN sellers s ON s.id = m.seller_id 108 | JOIN quantity q ON q.model_id = m.id 109 | JOIN manufacturers mn ON mn.id = m.manufacturer_id 110 | GROUP BY s.id 111 | ORDER BY SUM(q.count) 112 | DESC 113 | LIMIT 1) 114 | 115 | -------------------------------------------------------------------------------- /Lesson-4.java: -------------------------------------------------------------------------------- 1 | // Math 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | 7 | double pi = Math.PI; 8 | double e = Math.E; 9 | 10 | double result1 = Math.cos(0); 11 | double result2 = Math.sin(0); 12 | 13 | double result3 = Math.sqrt(8); 14 | double result4 = Math.pow(3, 4); 15 | 16 | System.out.println(pi); // 3.14 17 | System.out.println(e); // 2.71 18 | System.out.println(result1); // 1 19 | System.out.println(result2); // 0 20 | System.out.println(result3); // 2.82 21 | System.out.println(result4); // 81 22 | } 23 | } 24 | 25 | 26 | // Task #1 27 | import java.util.*; 28 | 29 | public class Main { 30 | public static void main(String[] args) { 31 | 32 | double r = 4; 33 | 34 | double C = 2 * Math.PI * r; 35 | 36 | System.out.println(C); 37 | } 38 | } 39 | 40 | 41 | // Task #3 42 | import java.util.*; 43 | 44 | public class Main { 45 | public static void main(String[] args) { 46 | 47 | int number = 405; 48 | 49 | int s = number / 100; 50 | int d = number / 10 % 10; 51 | int e = number % 10; 52 | 53 | System.out.printf("%d = %d*100 + %d*10 + %d\n", number, s, d, e); 54 | 55 | int sum = s + d + e; 56 | int multiplication = s * d * e; 57 | 58 | System.out.println("Sum = " + sum); 59 | System.out.println("Multiplication = " + multiplication); 60 | } 61 | } 62 | 63 | 64 | // Операции сравнения 65 | import java.util.*; 66 | 67 | public class Main { 68 | public static void main(String[] args) { 69 | 70 | int a = 20; 71 | int b = 10; 72 | 73 | boolean result1 = (a == b); // false 74 | boolean result2 = (a != b); // true 75 | boolean result3 = (a > b); // true 76 | boolean result4 = (a <= b); // false 77 | 78 | System.out.println(result1); 79 | System.out.println(result2); 80 | System.out.println(result3); 81 | System.out.println(result4); 82 | } 83 | } 84 | 85 | // Логичечкие операции 86 | import java.util.*; 87 | 88 | public class Main { 89 | public static void main(String[] args) { 90 | 91 | int a = 20; 92 | int b = 10; 93 | 94 | boolean result1 = ((a > 10) && (b > 10)); // false 95 | boolean result2 = ((a > 10) && (b >= 10)); // true 96 | 97 | boolean result3 = ((a > 10) || (b > 10)); // true 98 | boolean result4 = ((a > 20) || (b > 10)); // false 99 | 100 | System.out.println(result1); 101 | System.out.println(result2); 102 | System.out.println(result3); 103 | System.out.println(result4); 104 | } 105 | } 106 | 107 | // Task #5 108 | import java.util.*; 109 | 110 | public class Main { 111 | public static void main(String[] args) { 112 | 113 | int number = 2452247; 114 | 115 | boolean isEven = (number % 2 == 0); 116 | boolean isEndedBySeven = (number % 10 == 7); 117 | 118 | System.out.printf("Number %d is even? %b\n", number, isEven); 119 | System.out.printf("Number %d is ended by 7? %b\n", number, isEndedBySeven); 120 | } 121 | } 122 | 123 | // if/else 124 | import java.util.*; 125 | 126 | public class Main { 127 | public static void main(String[] args) { 128 | 129 | int a = 10; 130 | 131 | if(a > 0) 132 | { 133 | System.out.println("Данное число больше 0"); 134 | } 135 | } 136 | } 137 | 138 | // if/else 139 | import java.util.*; 140 | 141 | public class Main { 142 | public static void main(String[] args) { 143 | 144 | double a = 0.0; 145 | 146 | if(a > 0) { 147 | System.out.println("Данное число больше 0"); 148 | } 149 | else { 150 | System.out.println("Данное число не больше 0"); 151 | } 152 | } 153 | } 154 | 155 | // Task #6 156 | import java.util.*; 157 | 158 | public class Main { 159 | public static void main(String[] args) { 160 | 161 | int a = 16; 162 | int b = 2; 163 | 164 | System.out.println("a = " + a); 165 | System.out.println("b = " + b); 166 | 167 | if(Math.abs(a) > Math.abs(b)) { 168 | a = a / 2; 169 | } 170 | 171 | System.out.println("a = " + a); 172 | } 173 | } 174 | 175 | // Task #8 176 | import java.util.*; 177 | 178 | public class Main { 179 | public static void main(String[] args) { 180 | 181 | int day = 17; 182 | 183 | switch(day) 184 | { 185 | case 1: // day = 1 186 | System.out.println("Это - понедельник"); 187 | break; 188 | case 2: 189 | System.out.println("Это - вторник"); 190 | break; 191 | case 3: 192 | System.out.println("Это - среда"); 193 | break; 194 | case 4: 195 | System.out.println("Это - четверг"); 196 | break; 197 | case 5: 198 | System.out.println("Это - пятница"); 199 | break; 200 | case 6: 201 | System.out.println("Это - суббота"); 202 | break; 203 | case 7: 204 | System.out.println("Это - воскресенье"); 205 | break; 206 | 207 | default: 208 | System.out.println("Не существует такого дня!"); 209 | break; 210 | } 211 | } 212 | } 213 | 214 | 215 | // Task #7 (вариант №1) 216 | 217 | import java.util.*; 218 | 219 | public class Main { 220 | public static void main(String[] args) { 221 | 222 | int weight = 35; 223 | 224 | if(weight <= 0) { 225 | System.out.println("Вес невалиден!"); 226 | } 227 | else 228 | if(weight < 37) { 229 | System.out.println("Иди и набирай вес!"); 230 | } 231 | else 232 | if(weight < 60) { 233 | System.out.println("Легкий вес"); 234 | } 235 | else 236 | if(weight < 75) { 237 | System.out.println("Средний вес"); 238 | } 239 | else 240 | if(weight < 91) { 241 | System.out.println("Тяжелый вес"); 242 | } 243 | else { 244 | System.out.println("Супертяжелый вес"); 245 | } 246 | } 247 | } -------------------------------------------------------------------------------- /Lesson-40.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `stc-22-17`.`phones` ( 2 | `id` INT NOT NULL, 3 | `manufacturer` VARCHAR(45) NOT NULL, 4 | `model` VARCHAR(45) NOT NULL, 5 | `price` INT NULL, 6 | `quantity` INT NOT NULL DEFAULT 0, 7 | PRIMARY KEY (`id`)); 8 | 9 | 10 | 11 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('1', 'Apple', 'iPhone 13', '100000', '5'); 12 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('2', 'Apple', 'iPhone 12', '90000', '4'); 13 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('3', 'Apple', 'iPhone XR', '40000', '10'); 14 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('4', 'Samsung', 'Galaxy Note S10', '120000', '5'); 15 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('5', 'Samsung', 'A310', '30000', '8'); 16 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('6', 'Samsung', 'Fold', '200000', '2'); 17 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('7', 'Realme', 'X31', '40000', '15'); 18 | INSERT INTO `stc-22-17`.`phones` (`id`, `manufacturer`, `model`, `price`, `quantity`) VALUES ('8', 'Motorola', 'E398', '50000', '3'); 19 | 20 | 21 | 22 | CREATE DEFINER=`root`@`localhost` PROCEDURE `select_all_phones`() 23 | BEGIN 24 | SELECT * FROM `stc-22-17`.phones; 25 | END 26 | 27 | 28 | CREATE DEFINER=`root`@`localhost` PROCEDURE `find_most_expensive_phone`() 29 | BEGIN 30 | SELECT * FROM `stc-22-17`.phones 31 | WHERE price = (SELECT MAX(price) FROM `stc-22-17`.phones); 32 | END 33 | 34 | 35 | 36 | CREATE DEFINER=`root`@`localhost` PROCEDURE `find_phones_in_range`(IN first_price INTEGER, IN second_price INTEGER) 37 | BEGIN 38 | IF first_price > second_price 39 | THEN 40 | SELECT * FROM `stc-22-17`.phones WHERE price BETWEEN second_price AND first_price; 41 | ELSE 42 | SELECT * FROM `stc-22-17`.phones WHERE price BETWEEN first_price AND second_price; 43 | END IF; 44 | END 45 | 46 | 47 | CREATE DEFINER=`root`@`localhost` PROCEDURE `add_phone`(IN id integer, IN manufacturer varchar(50), IN model varchar(50), IN price integer, IN quantity integer) 48 | BEGIN 49 | INSERT INTO `stc-22-17`.`phones` (`id`,`manufacturer`,`model`,`price`,`quantity`) 50 | VALUES (id, manufacturer, model, price, quantity); 51 | END 52 | 53 | 54 | CREATE DEFINER=`root`@`localhost` FUNCTION `find_max_id`() RETURNS int 55 | DETERMINISTIC 56 | BEGIN 57 | DECLARE maxID integer; 58 | SELECT MAX(id) INTO maxID FROM `stc-22-17`.phones; 59 | RETURN maxID; 60 | END 61 | 62 | 63 | 64 | CREATE DEFINER=`root`@`localhost` PROCEDURE `add_phone_without_id`(IN manufacturer varchar(50), IN model varchar(50), IN price integer, IN quantity integer) 65 | BEGIN 66 | DECLARE id integer; 67 | SET id = `stc-22-17`.find_max_id() + 1; 68 | 69 | INSERT INTO `stc-22-17`.`phones` (`id`,`manufacturer`,`model`,`price`,`quantity`) 70 | VALUES (id, manufacturer, model, price, quantity); 71 | END 72 | 73 | 74 | CREATE DEFINER=`root`@`localhost` PROCEDURE `update_prices`() 75 | BEGIN 76 | UPDATE `stc-22-17`.phones 77 | SET price = price * 0.9 78 | WHERE quantity > 0 AND quantity < 3; 79 | END -------------------------------------------------------------------------------- /Lesson-5.java: -------------------------------------------------------------------------------- 1 | // FOR 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | 7 | for(int i = 0; i < 10; i++) { 8 | System.out.println("Test message"); 9 | } 10 | 11 | } 12 | } 13 | 14 | // FOR 15 | import java.util.*; 16 | 17 | public class Main { 18 | public static void main(String[] args) { 19 | 20 | for(int i = -5; i <= 0; i++) { 21 | System.out.println("Test message"); 22 | } 23 | 24 | } 25 | } 26 | 27 | // FOR 28 | import java.util.*; 29 | 30 | public class Main { 31 | public static void main(String[] args) { 32 | 33 | for(int i = 0; i < 10; i = i + 3) { 34 | System.out.print(i + " "); 35 | } 36 | } 37 | } 38 | 39 | // FOR 40 | import java.util.*; 41 | 42 | public class Main { 43 | public static void main(String[] args) { 44 | 45 | for(int i = 1; i < 10; i = i * 2) { 46 | System.out.print(i + " "); 47 | } 48 | } 49 | } 50 | 51 | // Task #1 52 | import java.util.*; 53 | 54 | public class Main { 55 | public static void main(String[] args) { 56 | 57 | for(int i = 0; i < 10; i++) { 58 | System.out.print("20 "); 59 | } 60 | } 61 | } 62 | 63 | 64 | // Task #2 65 | 66 | import java.util.*; 67 | 68 | public class Main { 69 | public static void main(String[] args) { 70 | 71 | for(int i = 10; i <= 25; i++) { 72 | System.out.printf("%d %d.4\n", i, i); 73 | } 74 | } 75 | } 76 | 77 | // Task #3 78 | 79 | import java.util.*; 80 | 81 | public class Main { 82 | public static void main(String[] args) { 83 | 84 | for(int i = 1; i <= 9; i++) { 85 | System.out.printf("%d x 7 = %d\n", i, i*7); 86 | } 87 | } 88 | } 89 | 90 | // Task #4.1 91 | /* 92 | Найти сумму всех целых чисел от 100 до 500 93 | */ 94 | 95 | import java.util.*; 96 | 97 | public class Main { 98 | public static void main(String[] args) { 99 | 100 | int sum = 0; 101 | 102 | for(int i = 100; i <= 500; i++) { 103 | System.out.println("===================="); 104 | System.out.println("i = " + i); 105 | System.out.println("Сумма до внесения изменений " + sum); 106 | sum = sum + i; 107 | System.out.println("Сумма после внесения изменений " + sum); 108 | } 109 | 110 | System.out.println("Сумма диапозона равна " + sum); 111 | } 112 | } 113 | 114 | // Task #5 115 | import java.util.Scanner; 116 | import java.util.*; 117 | 118 | public class Main { 119 | public static void main(String[] args) { 120 | 121 | Scanner sc = new Scanner(System.in); 122 | 123 | int n = 10; 124 | 125 | double sum = 0; 126 | 127 | for(int i = 0; i < n; i++) { 128 | System.out.println("============="); 129 | System.out.println("i = " + i); 130 | double temp = sc.nextDouble(); 131 | System.out.println(temp); 132 | sum = sum + temp; 133 | } 134 | 135 | double avg = sum / n; 136 | 137 | System.out.printf("AVG = %.2f", avg); 138 | } 139 | } 140 | 141 | // DO (WHILE) 142 | import java.util.*; 143 | 144 | public class Main { 145 | public static void main(String[] args) { 146 | 147 | int i = 0; 148 | 149 | do { 150 | System.out.print(i + " "); 151 | i++; 152 | } 153 | while(i < 10); 154 | } 155 | } 156 | 157 | // WHILE 158 | import java.util.*; 159 | 160 | public class Main { 161 | public static void main(String[] args) { 162 | 163 | int i = 0; 164 | 165 | while(i < 10) { 166 | System.out.print(i + " "); 167 | i++; 168 | } 169 | } 170 | } 171 | 172 | // Task #7 173 | 174 | import java.util.*; 175 | import java.util.Scanner; 176 | 177 | public class Main { 178 | public static void main(String[] args) { 179 | 180 | int sum = 0; 181 | int count = 0; 182 | 183 | Scanner sc = new Scanner(System.in); 184 | 185 | int temp = sc.nextInt(); 186 | 187 | while(temp != 0) { 188 | // System.out.println("============="); 189 | // System.out.println("Scanning " + temp); 190 | sum = sum + temp; 191 | count++; 192 | temp = sc.nextInt(); 193 | } 194 | 195 | System.out.printf("Сумма ряда %d. Количество чисел %d", sum, count); 196 | 197 | } 198 | } 199 | 200 | // Найти сумму всего ряда чисел 201 | 202 | import java.util.*; 203 | import java.util.Scanner; 204 | 205 | public class Main { 206 | public static void main(String[] args) { 207 | 208 | int sum = 0; 209 | int count = 0; 210 | 211 | Scanner sc = new Scanner(System.in); 212 | 213 | while(sc.hasNext() == true) { 214 | int temp = sc.nextInt(); 215 | sum = sum + temp; 216 | count++; 217 | } 218 | 219 | System.out.printf("Сумма ряда %d. Количество чисел %d", sum, count); 220 | } 221 | } 222 | 223 | // Task #8 224 | 225 | import java.util.*; 226 | 227 | public class Main { 228 | public static void main(String[] args) { 229 | 230 | int number = -151232; 231 | int countOfThree = 0; 232 | 233 | System.out.println("Оригинальное число " + number); 234 | 235 | number = Math.abs(number); 236 | 237 | while(number != 0) { 238 | int ending = number % 10; 239 | 240 | if(ending == 3) { 241 | countOfThree++; 242 | } 243 | 244 | number = number / 10; 245 | } 246 | 247 | System.out.println("Цифра 3 встречается в нем " + countOfThree + " раз"); 248 | } 249 | } 250 | 251 | // Task #11 252 | 253 | import java.util.*; 254 | 255 | public class Main { 256 | public static void main(String[] args) { 257 | 258 | for(int i = 5000; i > 0; i--) { 259 | if(i % 39 == 0) { 260 | System.out.println(i); 261 | break; 262 | } 263 | } 264 | } 265 | } 266 | 267 | -------------------------------------------------------------------------------- /Lesson-6.java: -------------------------------------------------------------------------------- 1 | // Functions & Methods 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | public static void print(int value) { 7 | 8 | System.out.println(value); 9 | } 10 | 11 | public static void printMax(int a, int b) { 12 | 13 | if(a > b) 14 | System.out.println("Большее число " + a); 15 | else 16 | if(a < b) 17 | System.out.println("Большее число " + b); 18 | else 19 | System.out.println("Числа одинаковые"); 20 | } 21 | 22 | public static int max(int numberOne, int numberTwo) { 23 | 24 | if(numberOne > numberTwo) 25 | return numberOne; 26 | else 27 | return numberTwo; 28 | } 29 | 30 | public static void main(String[] args) { 31 | 32 | int x = 100; 33 | int y = 20; 34 | 35 | int maximum = max(x,y); 36 | print(maximum); 37 | 38 | int v1 = 9; 39 | int v2 = 11; 40 | print(max(9,11)); 41 | 42 | int a = 10; 43 | int b = 20; 44 | int c = 20; 45 | 46 | printMax(a,b); 47 | printMax(c,a); 48 | printMax(b,c); 49 | } 50 | } 51 | 52 | // Task #1 53 | import java.util.*; 54 | 55 | public class Main { 56 | 57 | public static void printNumber(int number, int columns, int rows) { 58 | 59 | for(int i = 0; i < rows; i++) { 60 | for(int j = 0; j < columns; j++) { 61 | System.out.print(number + " "); 62 | } 63 | System.out.println(); 64 | } 65 | } 66 | 67 | public static void printText(String line, int columns, int rows) { 68 | 69 | for(int i = 0; i < rows; i++) { 70 | for(int j = 0; j < columns; j++) { 71 | System.out.print(line + " "); 72 | } 73 | System.out.println(); 74 | } 75 | } 76 | 77 | public static void main(String[] args) { 78 | 79 | printNumber(5, 6, 4); 80 | printText("Hi", 3, 3); 81 | } 82 | } 83 | 84 | 85 | // Task #3 86 | import java.util.*; 87 | 88 | public class Main { 89 | 90 | public static void printElement(int a, int b) { 91 | 92 | System.out.printf("%d + %d = %d\t", a, b, a + b); 93 | } 94 | 95 | public static void printLine(int n) { 96 | 97 | for(int i = 1; i <= 9; i++) { 98 | printElement(n, i); 99 | } 100 | System.out.println(); 101 | } 102 | 103 | public static void printTable() { 104 | 105 | for(int i = 1; i <=9; i++) { 106 | printLine(i); 107 | } 108 | } 109 | 110 | public static void main(String[] args) { 111 | 112 | printTable(); 113 | } 114 | } 115 | 116 | 117 | // Task #5 118 | import java.util.*; 119 | 120 | public class Main { 121 | 122 | public static long factorialClassic(int n) { 123 | 124 | long result = 1; 125 | 126 | for(int i = 1; i <= n; i++) { 127 | result = result * i; 128 | } 129 | 130 | return result; 131 | } 132 | 133 | public static long factorialRecursion(int n) { 134 | 135 | if(n == 1) 136 | return 1; 137 | else 138 | return n * factorialRecursion(n - 1); 139 | } 140 | 141 | public static void main(String[] args) { 142 | System.out.println(factorialClassic(1)); 143 | System.out.println(factorialClassic(3)); 144 | System.out.println(factorialClassic(5)); 145 | System.out.println(factorialClassic(13)); 146 | 147 | System.out.println(factorialRecursion(1)); 148 | System.out.println(factorialRecursion(3)); 149 | System.out.println(factorialRecursion(5)); 150 | System.out.println(factorialRecursion(13)); 151 | } 152 | } 153 | 154 | // Task #6 155 | import java.util.*; 156 | 157 | public class Main { 158 | 159 | public static int max(int a, int b) { 160 | // int max(int, int) 161 | if(a > b) 162 | return a; 163 | else 164 | return b; 165 | } 166 | 167 | public static double max(double a, double b) { 168 | // double max(double, double) 169 | if(a > b) 170 | return a; 171 | else 172 | return b; 173 | } 174 | 175 | public static int max(int a, int b, int c) { 176 | // int max(int, int, int) 177 | return max(max(a, b), c); 178 | } 179 | 180 | public static int max(int a, int b, int c, int d) { 181 | // int max(int, int, int, int) 182 | return max(max(a, b), max(c, d)); 183 | } 184 | 185 | public static void main(String[] args) { 186 | 187 | System.out.println(max(5,7)); // 7 188 | System.out.println(max(-1,-3)); // -1 189 | 190 | System.out.println(max(1, 2, 3)); // 3 191 | System.out.println(max(1, 4, 3)); // 4 192 | System.out.println(max(5, 2, 3)); // 5 193 | 194 | System.out.println(max(1, 2, 3, 4)); // 4 195 | System.out.println(max(7, 10, 13, 5)); // 13 196 | System.out.println(max(11, 21, 13, 14)); // 21 197 | System.out.println(max(31, 22, 13, 24)); // 31 198 | 199 | System.out.println(max(1.5, 2.5)); // 2.5 200 | 201 | 202 | } 203 | } 204 | 205 | // Task #7 206 | import java.util.*; 207 | 208 | public class Main { 209 | 210 | public static boolean isTriangle(double a, double b, double c) { 211 | 212 | if((a > 0) && (b > 0) && (c > 0) && (a + b > c) && (a + c > b) && (b + c > a)) 213 | return true; 214 | else 215 | return false; 216 | } 217 | 218 | public static double perimetr(double a, double b, double c) { 219 | 220 | if(isTriangle(a, b, c) == true) 221 | return a + b + c; 222 | else 223 | return 0; 224 | } 225 | 226 | public static double square(double a, double b, double c) { 227 | 228 | if(isTriangle(a, b, c) == true) { 229 | double p = perimetr(a, b, c) / 2; 230 | 231 | double s = Math.sqrt(p*(p-a)*(p-b)*(p-c)); 232 | 233 | return s; 234 | } 235 | else 236 | return 0; 237 | 238 | } 239 | 240 | public static void printInfo(double a, double b, double c) { 241 | 242 | if(isTriangle(a, b, c) == true) { 243 | System.out.printf("Треугольник со сторонами %.2f, %.2f, %.2f существует\n", a, b, c); 244 | System.out.printf("Площадь равна %.2f, периметр равен %.2f\n", square(a,b,c), perimetr(a,b,c)); 245 | } 246 | else 247 | System.out.printf("Треугольник со сторонами %.2f, %.2f, %.2f не существует\n", a, b, c); 248 | } 249 | 250 | public static void main(String[] args) { 251 | 252 | printInfo(3,4,5); 253 | printInfo(-3,-4,-5); 254 | printInfo(3,4,7); 255 | printInfo(1,1,1); 256 | 257 | } 258 | } -------------------------------------------------------------------------------- /Lesson-9.java: -------------------------------------------------------------------------------- 1 | // Arrays 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | 7 | int[] array1 = new int[5]; 8 | // System.out.println(array1[0]); 9 | 10 | array1[3] = 5; 11 | array1[0] = 1; 12 | 13 | System.out.println(array1[0]); 14 | System.out.println(array1[1]); 15 | System.out.println(array1[2]); 16 | System.out.println(array1[3]); 17 | System.out.println(array1[4]); 18 | 19 | /* 20 | String[] array2 = new String[5]; 21 | System.out.println(array2[0]); 22 | */ 23 | } 24 | } 25 | 26 | import java.util.*; 27 | 28 | public class Main { 29 | public static void main(String[] args) { 30 | 31 | int[] array1 = {1, 3, 5, 6, 8, 10, 12, 15, 0, 1}; 32 | 33 | int l = array1.length; 34 | 35 | System.out.println(l); 36 | } 37 | } 38 | 39 | import java.util.*; 40 | 41 | public class Main { 42 | 43 | public static void printArray(int[] array) { 44 | for(int i = 0; i < array.length; i++) { 45 | System.out.print(array[i] + " "); 46 | } 47 | System.out.println(); 48 | } 49 | 50 | public static void main(String[] args) { 51 | 52 | int[] array1 = {1, 3, 5, 6, 8, 10, 12, 15, 0, 1}; 53 | 54 | printArray(array1); 55 | } 56 | } 57 | 58 | // Task #1 59 | import java.util.*; 60 | import java.util.Scanner; 61 | 62 | public class Main { 63 | 64 | public static void printArray(int[] array) { 65 | for(int i = 0; i < array.length; i++) { 66 | System.out.print(array[i] + " "); 67 | } 68 | System.out.println(); 69 | } 70 | 71 | public static int[] scanArray(int n) { 72 | 73 | int[] array = new int[n]; 74 | Scanner sc = new Scanner(System.in); 75 | 76 | for(int i = 0; i < array.length; i++) { 77 | array[i] = sc.nextInt(); 78 | } 79 | 80 | return array; 81 | } 82 | 83 | public static void main(String[] args) { 84 | 85 | int[] array = scanArray(10); 86 | 87 | printArray(array); 88 | 89 | } 90 | } 91 | 92 | // Task #2 93 | 94 | import java.util.*; 95 | import java.util.Scanner; 96 | import java.util.Random; 97 | 98 | public class Main { 99 | 100 | public static void printArray(int[] array) { 101 | for(int i = 0; i < array.length; i++) { 102 | System.out.print(array[i] + " "); 103 | } 104 | System.out.println(); 105 | } 106 | 107 | public static int[] scanArray(int n) { 108 | 109 | int[] array = new int[n]; 110 | Scanner sc = new Scanner(System.in); 111 | 112 | for(int i = 0; i < array.length; i++) { 113 | array[i] = sc.nextInt(); 114 | } 115 | 116 | return array; 117 | } 118 | 119 | public static int[] generateArray(int n) { 120 | 121 | int[] array = new int[n]; 122 | Random r = new Random(); 123 | 124 | for(int i = 0; i < array.length; i++) { 125 | array[i] = r.nextInt(100); // 0 - 100 126 | } 127 | 128 | return array; 129 | } 130 | 131 | public static void main(String[] args) { 132 | 133 | int[] array = generateArray(10); 134 | 135 | printArray(array); 136 | 137 | } 138 | } 139 | 140 | // Task #4 141 | import java.util.*; 142 | import java.util.Scanner; 143 | import java.util.Random; 144 | 145 | public class Main { 146 | 147 | public static void printArray(double[] array) { 148 | for(int i = 0; i < array.length; i++) { 149 | System.out.printf("%.2f\t", array[i]); 150 | } 151 | System.out.println(); 152 | } 153 | 154 | public static double[] scanArray(int n) { 155 | 156 | double[] array = new double[n]; 157 | Scanner sc = new Scanner(System.in); 158 | 159 | for(int i = 0; i < array.length; i++) { 160 | array[i] = sc.nextDouble(); 161 | } 162 | 163 | return array; 164 | } 165 | 166 | public static double[] generateArray(int n) { 167 | 168 | double[] array = new double[n]; 169 | Random r = new Random(); 170 | 171 | for(int i = 0; i < array.length; i++) { 172 | array[i] = r.nextInt(100); // 0 - 100 173 | } 174 | 175 | return array; 176 | } 177 | 178 | public static double[] multiplyArrayByNumber(double[] array, double number) { 179 | 180 | for(int i = 0; i < array.length; i++) { 181 | array[i] = array[i] * number; 182 | } 183 | 184 | return array; 185 | } 186 | 187 | public static double[] decreaseArrayByNumber(double[] array, double number) { 188 | 189 | for(int i = 0; i < array.length; i++) { 190 | array[i] = array[i] - number; 191 | } 192 | 193 | return array; 194 | } 195 | 196 | public static double[] divideArrayByFirstElement(double[] array) { 197 | 198 | double temp = array[0]; 199 | 200 | for(int i = 0; i < array.length; i++) { 201 | array[i] = array[i] / temp; 202 | } 203 | 204 | return array; 205 | } 206 | 207 | public static void main(String[] args) { 208 | 209 | double[] array = generateArray(5); 210 | printArray(array); 211 | 212 | multiplyArrayByNumber(array, 5); 213 | printArray(array); 214 | 215 | decreaseArrayByNumber(array, 15); 216 | printArray(array); 217 | 218 | divideArrayByFirstElement(array); 219 | printArray(array); 220 | } 221 | } 222 | 223 | // Task #5.1 224 | import java.util.*; 225 | import java.util.Scanner; 226 | import java.util.Random; 227 | 228 | public class Main { 229 | 230 | public static void printArray(double[] array) { 231 | for(int i = 0; i < array.length; i++) { 232 | System.out.printf("%.2f\t", array[i]); 233 | } 234 | System.out.println(); 235 | } 236 | 237 | public static double[] scanArray(int n) { 238 | 239 | double[] array = new double[n]; 240 | Scanner sc = new Scanner(System.in); 241 | 242 | for(int i = 0; i < array.length; i++) { 243 | array[i] = sc.nextDouble(); 244 | } 245 | 246 | return array; 247 | } 248 | 249 | public static double[] generateArray(int n) { 250 | 251 | double[] array = new double[n]; 252 | Random r = new Random(); 253 | 254 | for(int i = 0; i < array.length; i++) { 255 | array[i] = r.nextInt(100); // 0 - 100 256 | } 257 | 258 | return array; 259 | } 260 | 261 | public static void printNonNegativeNumbers(double[] array) { 262 | for(int i = 0; i < array.length; i++) { 263 | if(array[i] >= 0) { 264 | System.out.print(array[i] + "\t"); 265 | } 266 | } 267 | System.out.println(); 268 | } 269 | 270 | public static void main(String[] args) { 271 | 272 | double[] array = {-2, 0, -3, -6, 5, -3}; 273 | printArray(array); 274 | 275 | printNonNegativeNumbers(array); 276 | } 277 | } 278 | 279 | // Task #6 280 | import java.util.*; 281 | import java.util.Scanner; 282 | import java.util.Random; 283 | 284 | public class Main { 285 | 286 | public static void printArray(double[] array) { 287 | for(int i = 0; i < array.length; i++) { 288 | System.out.printf("%.2f\t", array[i]); 289 | } 290 | System.out.println(); 291 | } 292 | 293 | public static double[] generateArray(int n) { 294 | 295 | double[] array = new double[n]; 296 | Random r = new Random(); 297 | 298 | for(int i = 0; i < array.length; i++) { 299 | array[i] = r.nextInt(100); // 0 - 100 300 | } 301 | 302 | return array; 303 | } 304 | 305 | public static double findMaxElement(double[] array) { 306 | 307 | double max = array[0]; 308 | 309 | for(int i = 1; i < array.length; i++) { 310 | if(array[i] > max) { 311 | max = array[i]; 312 | } 313 | } 314 | 315 | return max; 316 | } 317 | 318 | public static int findIndexOfMaxElement(double[] array) { 319 | 320 | int index = 0; 321 | 322 | double max = findMaxElement(array); 323 | 324 | for(int i = 0; i < array.length; i++) { 325 | if(array[i] == max) { 326 | index = i; 327 | break; 328 | } 329 | } 330 | 331 | return index; 332 | } 333 | 334 | public static void main(String[] args) { 335 | 336 | double[] array = {5, 7, 8, 7, 8, 3}; 337 | printArray(array); 338 | 339 | System.out.println(findMaxElement(array)); 340 | System.out.println(findIndexOfMaxElement(array)); 341 | } 342 | } 343 | 344 | // Task #7 345 | import java.util.*; 346 | import java.util.Scanner; 347 | import java.util.Random; 348 | 349 | public class Main { 350 | 351 | public static void printArray(double[] array) { 352 | for(int i = 0; i < array.length; i++) { 353 | System.out.printf("%.2f\t", array[i]); 354 | } 355 | System.out.println(); 356 | } 357 | 358 | public static double[] generateArray(int n) { 359 | 360 | double[] array = new double[n]; 361 | Random r = new Random(); 362 | 363 | for(int i = 0; i < array.length; i++) { 364 | array[i] = r.nextInt(100); // 0 - 100 365 | } 366 | 367 | return array; 368 | } 369 | 370 | public static double[] swapElements(double[] array, int index1, int index2) { 371 | 372 | if((index1 >= array.length) || (index2 >= array.length)) { 373 | return array; 374 | } 375 | else { 376 | double temp = array[index1]; 377 | array[index1] = array[index2]; 378 | array[index2] = temp; 379 | 380 | return array; 381 | } 382 | } 383 | 384 | public static void main(String[] args) { 385 | 386 | double[] array = generateArray(7); 387 | printArray(array); 388 | 389 | swapElements(array, 1, 4); 390 | printArray(array); 391 | 392 | swapElements(array, 0, 5); 393 | printArray(array); 394 | 395 | swapElements(array, 2, 8); 396 | printArray(array); 397 | 398 | } 399 | } 400 | 401 | // 402 | https://codeboard.io/projects/343422 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # testing20220802 2 | 3 | Где писать код: 4 | - https://onecompiler.com/java 5 | - https://www.tutorialspoint.com/compile_java_online.php 6 | 7 | 8 | 9 | Работать с кодом (локально): 10 | - https://code.visualstudio.com/ 11 | - https://notepad-plus-plus.org/downloads/ (Windows only) 12 | - https://www.sublimetext.com/ (MacOS only) 13 | 14 | Работа с ООП: 15 | - https://codeboard.io/ 16 | 17 | Примеры ООП: 18 | - Люди, ноутбуки и прочие: https://codeboard.io/projects/342068 19 | - Абстрактные животные: https://codeboard.io/projects/342564 20 | - Треугольники: https://codeboard.io/projects/342575 21 | 22 | Unit-tests: 23 | - https://codeboard.io/projects/344221 24 | - https://codeboard.io/projects/344225 25 | - https://codeboard.io/projects/341274 26 | --------------------------------------------------------------------------------