Закрыть
×
=0) { let js = text.slice(pos1, pos2); + '<\/' + "script" + '>'; arrText.push(js); // next pos1 = pos2; continue; } } } break; } return arrText; } function OpenDialog(parentDiv, urlContent) { parentDiv = document.getElementById('modal-background'); // new !!!!!!! parentDiv.appendChild(document.getElementById('modal-template')); document.getElementById('modal-background').style.display = "flex"; // !!!!! block document.getElementById('modal-template').style.display = "flex"; // !!!!! document.getElementById('modal-body').innerHTML = ""; post_url(urlContent, "", function(text_from_server) { var element = document.getElementById('modal-body'); element.innerHTML = text_from_server; // add scripts var arrJSText = get_scripts(text_from_server); for (var i=0; i
dir.by
Праздники ...
Праздники ...
День города Минска (2-ая суббота сентября) (9 и 10 сентября 2023)
Концерты, выставки ...
Концерты, выставки ...
Музыка шоу при свечах "Music of Ludovico Einaudi"|||г. Минск 28 марта, 25 апреля, 28 июня, 26 июля, 9 августа 2026
Афишу
Спорт занятия ...
Спорт занятия ...
Катание на лыжах !!!
Спорт занятие
Компьютер, программы...
Компьютер, программы...
Объявления ...
Объявления ...
Ремонт КПП МТЗ-2022
Объявление
Новости ...
Новости ...
Форум ...
Форум ...
обсуждение...
Поиск
Концерты
Спорт
Форум
Компьютер
Компьютер, программы
→
Kotlin
fun() { ... } is a function in Kotlin
посмотрели
265
раз
обновлено: 12 July 2026
The function is needed to perform an action.
Example 1
Function
input parameters
NO
return value
NO
Kotlin
fun
Name()
{
}
Full example:
Creating a new console application in Kotlin...
Kotlin
// My Function
fun
showWeather
()
{
println(
"today 20 degree"
);
}
fun
main
() {
showWeather()
// call my function
// on the screen we will see:
today 20 degree
}
Example 2
Function
input parameters
YES
return value
NO
Kotlin
fun
Name(
parameter1:Type1, parameter2:Type2
)
{
}
Full example:
Creating a new console application in Kotlin...
Kotlin
// My Function
fun
showMessage
(
text1:
String
, text2:
String
)
{
println(
"$text1 | $text2"
);
}
fun
main
() {
showMessage(
"Hello"
,
"thank you"
)
// call my function
// on the screen we will see:
Hello | thank you
}
Example 3
Function
input parameters
NO
return value
YES
Kotlin
fun
Name()
:type
{
return
}
Option 2. You can do it like this:
Kotlin
fun
Name()
:type =
Full example:
Creating a new console application in Kotlin...
Kotlin
// My Function
fun
priceBook
()
:
Int
{
return
20
}
fun
main
() {
val
my1:
Int
= priceBook()
// call my function and get the result
println(my1)
// on the screen we will see:
20
}
Option 2. You can do it like this:
Put
=
after the function and this is how the result will be returned
Kotlin
// My Function
fun
priceBook
()
:
Int
=
20
fun
main
() {
val
my1:
Int
= priceBook()
// call my function and get the result
println(my1)
// on the screen we will see:
20
}
Example 4
Function
input parameters
YES
return value
YES
Kotlin
fun
Name(
parameter1:Type1, parameter2:Type2
)
:type
{
return
}
Option 2. You can do it like this:
Kotlin
fun
Name(
parameter1:Type1, parameter2:Type2
)
:type =
Full example:
Creating a new console application in Kotlin...
Kotlin
// My Function
fun
calculateSum
(
a:Float, b:Float
)
: Float
{
return
a + b
}
fun
main
() {
val
my1 = calculateSum(1.2f, 3f)
// call my function and get the result
println(my1)
// on the screen we will see:
4.2
}
Option 2. You can do it like this:
Put
=
after the function and this is how the result will be returned
Kotlin
// My Function
fun
calculateSum
(
a:Float, b:Float
)
: Float
=
a+b
fun
main
() {
val
my1 = calculateSum(1.2f, 3f)
// call my function and get the result
println(my1)
// on the screen we will see:
4.2
}
← Previous topic
How do I find enum by value in Kotlin ?
Next topic →
Lambda function in Kotlin. Example 1: var myFunc1 : (a:Int, b:Int) -> Int = { p1, p2 -> p1 + p2 };
Your feedback ... Comments ...
Your Name
Your comment
(www links can only be added by a logged-in user)
+ Picture
Объявления
Объявления
•
What is Kotlin?
•
Why is IntelliJ IDEA the most popular development environment for Kotlin?
•
Download and install IntelliJ IDEA to explore Kotlin
•
Create a new console project to explore Kotlin | IntelliJ IDEA
Setting the value
•
Declare the variable and set the value in Kotlin | val, var, lateinit, constant: const val, global variable: companion object
null
•
null value, use the symbol ? and ?. and !! and ?: and !!. and ?. in Kotlin
Int, Float, Boolean, Char ...
•
Integer numbers in Kotlin are: Byte, UByte, Short, UShort, Int, UInt, Long, ULong
•
Decimal numbers in Kotlin are: Float, Double
•
A flag with values of true or false in Kotlin is: Boolean
•
The symbol in Kotlin is: Char
•
Convert number to text in Kotlin | Int → String
String
•
The string, the text in Kotlin is: String
•
Interpolate strings in Kotlin. Example: val address:String = "${street}, ${country}"
•
What is the difference between String and StringBuilder ?
Enum
•
What is an enumeration (enum) in Kotlin ?
•
How do I find enum by value in Kotlin ?
Function
•
fun() { ... } is a function in Kotlin. The function is needed to perform an action.
Lambda function
•
Lambda function in Kotlin. Example 1: var myFunc1 : (a:Int, b:Int) -> Int = { p1, p2 -> p1 + p2 };
Collections and Arrays
•
Create collections list, set, map and an array array in Kotlin
Class
•
What is class in Kotlin? Example: class MyBook { ... } | Primary and secondary constructor | block init
•
lateinit is a late initialization for the class field | Kotlin
•
class that inherits from interface in Kotlin | Example: class MyBook : IBook { ...}
•
Unnamed class that inherits from interface in Kotlin | Example: val book1 = object : IBook { ...}
•
Generic, template class in Kotlin | Example: class MyBook<T> { ... }
Writing a program
•
The Kotlin console app works like Android Jetpack Compose
Ваши вопросы присылайте по почте:
info@dir.by