This file contains 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
{ println("Hello")}() | |
//Hello | |
println("Hello") | |
//Hello | |
val swim = { println("swim \n")} | |
swim() | |
//swim |
This file contains 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
val decorations = listOf ("rock", "pagoda", "plastic plant", "alligator", "flowerpot") | |
println(decorations.filter {true}) | |
println(decorations.filter {it[0] == 'p'}) |
This file contains 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 java.util.* | |
fun main(args: Array<String>) { | |
println("Hello, ${args[0]}!") | |
readABook() | |
} | |
fun readABook() { | |
val day = randomDay() | |
val book = readBook(day) |
This file contains 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
fun readAStory() = println("Read a Story") | |
fun readAPoem() = println("Read a Poem") | |
var readStory = 0 | |
var readPoem = 0 | |
while (readStory < 5) { | |
readAStory() | |
readStory ++ | |
} |
This file contains 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
val read = listOf("story", "poem", "novel") | |
for (r in read) { // 1 | |
println("Read a $r .") | |
} |
This file contains 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
data class Person(var name: String, var age: Int, var about: String) { | |
constructor() : this("", 0, "") | |
} | |
fun writeCreationLog(person: Person) { | |
println("A new person ${person.name} was created.") | |
} | |
val adam = Person("Adam", 23, "Android developer") | |
.also { |
This file contains 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
class Company() { | |
var name: String | |
var objective: String | |
var founder: String | |
} | |
var company: Company? = null | |
company?.run { |
This file contains 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
final String msg = num > 10 ? "Number is greater than 10" : "Number is less than or equal to 10"; |
This file contains 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
data class Person(var name: String, var age: Int = 0, var city: String = "",var country: String = "") | |
val adam = Person("Adam").apply { | |
age = 24 | |
city = "Amsterdam" | |
country = "Germany" | |
} | |
with(adam){ | |
print("$age") | |
} |
This file contains 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
data class Person(var name: String, var age: Int = 0, var city: String = "",var country: String = "") | |
val adam = Person("Adam").apply { | |
age = 24 | |
city = "Amsterdam" | |
country = "Germany" | |
} | |
println(adam) |