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(""" | |
|SELECT * | |
|FROM User | |
|WHERE Age = 42 | |
""".trimMargin()) | |
/* Çıktısı: | |
SELECT * | |
FROM User | |
WHERE Age = 42 |
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 displayFence(character: Char = '#', length: Int = 15) { | |
for (i in 1..length) { | |
print(character) | |
} | |
} | |
fun main(args: Array<String>) { | |
// character değeri pas geçilerek çağırma | |
// Çıktısı: ##### | |
displayFence(length = 5) |
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 square(k: Int) = k * k | |
fun main(args: Array<String>) { | |
// Çıktısı: 25 | |
print(square(5)) | |
} |
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 tekMiCiftMi(sayi: Int) : String { | |
return when (sayi % 2) { | |
0 -> "Çift" | |
1 -> "Tek" | |
else -> { | |
throw IllegalArgumentException() | |
} | |
} | |
} |
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 tekMiCiftMi(sayi: Int) : String { | |
return when (sayi % 2) { | |
0, 1 -> "Tek veya çifttir" | |
else -> { | |
throw IllegalArgumentException() | |
} | |
} | |
} | |
fun main(args: Array<String>) { |
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 harfNotuHesapla(not: Int) : String { | |
return when (not) { | |
in 0..39 -> "FF" | |
in 40..49 -> "FD" | |
in 50..54 -> "DD" | |
in 55..59 -> "DC" | |
in 60..69 -> "CC" | |
in 70..79 -> "CB" | |
in 80..84 -> "BB" | |
in 85..89 -> "BA" |
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 isString(obj: Any): String { | |
return if (obj !is String) | |
"String değildir" | |
else | |
"String'tir." | |
} | |
fun main(args: Array<String>) { | |
// Çıktısı: String değildir | |
print(isString(40)) |
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 test(x: Any): Int { | |
if (x is String) { | |
return x.length | |
} else if (x is Array<*>) { | |
return x.size | |
} else if (x is Int) { | |
return x | |
} else { | |
throw IllegalArgumentException() | |
} |
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 tekMiCiftMi(sayi: Int) : String { | |
return when { | |
sayi % 2 == 0 -> "Çifttir" | |
sayi % 2 == 1 -> "Tektir" | |
else -> { | |
throw IllegalArgumentException() | |
} | |
} | |
} |
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 isMonday(x: Any) = when(x) { | |
is String -> x.startsWith("Mon") | |
else -> false | |
} | |
fun main(args: Array<String>) { | |
println(isMonday("Monday")) // true | |
println(isMonday(42)) // false | |
} |