This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
void main() { | |
StreamController<int> controller = new StreamController<int>(); | |
var stream = controller.stream.asBroadcastStream(); | |
var sink = controller.sink; | |
sink.add(1); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.2 Dart-Переменные | |
// 1) Создать глобальную переменную типа int с именем a; | |
// 2) Создать локальную переменную типа double с именем b; | |
// 3) Создать строковую переменную с именем text при помощи var, попытаться присвоить переменной a. Каков результат? (выведите его в консоль); | |
// 4) Создать целочисленную переменную с именем dyn при помощи dynamic, попытаться присвоить переменной строковое значение переменной text. Каков результат? (выведите его в консоль); | |
// 5) Создать переменную с именем fin при помощи final и con при помощи const, попытаться изменить переменные, посмотреть результат. В чем отличие final от const? | |
// 1 | |
int a; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.3 Базовые типы данных | |
// 1) Создать список var list = [1,2,3,4,5,6,7,8]; | |
// 2) Вывести длину этого списка; | |
// 3) Вывести отсортированный список list в порядке убывания, используя sort; | |
// 4) Выделить подсписок newList при помощи sublist (взять первые 3 элемента от исходного списка) и вывести на консоль; | |
// 5) Вывести индекс элемента со значением “5” в списке list; | |
// 6) Удалить значения с 8 до 5 из списка list и вывести в консоль. | |
void main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.4 Управляющие конструкции | |
// Используя switch, напишите программу в методе main(), которая выводит название месяца по номеру от 1 до 12. | |
void main() { | |
var monthNum = DateTime.now().month; | |
print(monthNum); | |
switch (monthNum) { | |
case DateTime.january: | |
print('january'); | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.4 Управляющие конструкции | |
// Используя циклы, напишите программу, которая выводит на консоль все четные числа от 0 до 100. | |
void main() { | |
// Прохидим все, выводим только четные | |
for (var i = 0; i < 100; i++) { | |
if (i.isEven) { | |
print(i); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:io'; | |
// 2.4 Управляющие конструкции | |
// Написать программу, которая слушает ввод в консоли, складывает вводимые пользователем числа. | |
// Если пользователь ввел stop, завершить приложение. | |
// Если пользователь вводит некорректные данные - прервать текущую итерацию, начать заново. | |
void main(List<String> arguments) { | |
var sum = 0.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.5 Функции | |
// Создайте текстовую переменную a = ‘hello world’; Напишите функцию, без возвращаемого значения. Функция меняет порядок слов на обратный. Например было ‘hello world’, стало ‘world hello’. | |
void main() { | |
var a = 'hello world'; | |
void reverse() { | |
a = a.split(' ').reversed.join(' '); | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.5 Функции | |
// Создайте и проинициализируйте массив чисел с произвольным размером. Напишите функцию, которая вычисляет среднее арифметическое число массива и возвращает double результат. Распечатайте результат в консоли. | |
void main() { | |
List<num> arrayList = [1, 2, 3, 4, 6]; | |
double average(List<num> arrayList) { | |
return arrayList.reduce((accumulator, current) => accumulator + current) / arrayList.length; | |
} | |
print(average(arrayList)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2.5 Функции | |
// Модернизируйте предыдущие функции так, чтобы на вход они принимали необходимые данные для работы. Параметр должен быть опциональным. | |
void main() { | |
String reverseText([String text]) { | |
return text?.split(' ')?.reversed?.join(' '); | |
} | |
double average([List<num> arrayList]) { | |
if (arrayList == null) return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
// 2.5 Функции | |
// Напишите функцию решения квадратного уравнения, используя вложенные функции. Вычисление дискриминанта, нахождение x1 и x2 выполните во вложенных функциях. Главная функция должна возвращать готовый результат. Функция возвращает ответ в строке (String). Есть три вида результата: | |
// Уравнение не имеет решения так как его дискриминант меньше нуля; | |
// Квадратное уравнение имеет единственное решение; | |
// Квадратное уравнение имеет два разных корня. | |
void main() { |
OlderNewer