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
/* | |
При инициализации простой переменной (числа, строки) значением тип можно не указывать, так как dart сам определит её тип. | |
Тип необходимо указывать если мы объявляем пустую переменную или работаем с коллекцией. | |
*/ | |
var a = 1; //глобальная перменная типа int | |
void main() { | |
var b = 2.0; //локальная перменная типа double | |
var text = 'Dart'; //локальная перменная типа String |
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
// Задание 1 | |
// Создайте целочисленную переменную с именем a проверить является ли число четным. | |
void main() { | |
const a = 7; | |
if (a.isEven) { | |
print('Число $a чётное'); | |
} else { |
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 | |
// Используете 32-битный символ Unicode u2665 выведите сообщение в консоль: I ♥ dart | |
void main() { | |
print('I \u2665 dart'); | |
} |
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
void main() { | |
// Создать список var list = [1,2,3,4,5,6,7,8]; | |
var list = [1, 2, 3, 4, 5, 6, 7, 8]; | |
// Вывести длину этого списка; | |
print('Элементов в списке: ${list.length}'); | |
// Вывести отсортированный список list в порядке убывания, используя sort; | |
list.sort((a, b) => b.compareTo(a)); | |
print(list); |
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
void main() { | |
// Задание 4 | |
// Создать Map телефонных номеров с именем numberBook и типом данных (“имя”: “номер телефона”), заполнить данными: Иван: 2264865, Татьяна: 89523366684, Олег: 84952256575. | |
// Вывести на экран весь телефонный справочник numberBook. | |
// Вставить новый номер в карту: Екатерина: 2359942 | |
var numberBook = <String, int>{ | |
'Иван': 2264865, | |
'Татьяна': 89523366684, | |
'Олег': 84952256575, |
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
void main() { | |
// Вывести на экран количество уникальных слов в тексте. | |
const text = ''' | |
She sells sea shells on the sea shore | |
The shells that she sells are sea shells I'm sure | |
So if she sells sea shells on the sea shore | |
I'm sure that the shells are sea shore shells | |
'''; | |
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
// Задание 1 | |
// Используя switch, напишите программу в методе main(), которая выводит название месяца по номеру от 1 до 12. | |
void main() { | |
const months = <int, String>{ | |
1: 'Январь', | |
2: 'Февраль', | |
3: 'Март', | |
4: 'Апрель', |
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 | |
// Используя циклы, напишите программу, которая выводит на консоль все четные числа от 0 до 100. | |
void main() { | |
var buffer = StringBuffer(); | |
for (var i = 0; i <= 100; i++) { | |
if (i.isEven) { | |
buffer.write('$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
// Задание 3 | |
// Написать программу, которая слушает ввод в консоли, складывает вводимые пользователем числа. | |
// Если пользователь ввел stop, завершить приложение. Если пользователь вводит некорректные | |
// данные - прервать текущую итерацию, начать заново. | |
import 'dart:io'; | |
void main() { | |
var total = 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
// Задание 4 | |
// Вывести на экран количество одинаковых слов в тексте. | |
void main() { | |
const text = ''' | |
She sells sea shells on the sea shore; | |
The shells that she sells are sea shells I'm sure. | |
So if she sells sea shells on the sea shore, | |
I'm sure that the shells are sea shore shells | |
'''; |
OlderNewer