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
fun main(args : Array<String>) { | |
for(i in 1..100) { | |
i.jojo() | |
} | |
} | |
private fun Int.jojo() { | |
val s = if(this.isPrime()) "JOJO!" else "$this" | |
println(s) | |
} |
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 javafx.application.Application | |
import javafx.event.ActionEvent | |
import javafx.geometry.Pos | |
import javafx.scene.Scene | |
import javafx.scene.control.Button | |
import javafx.scene.control.Label | |
import javafx.scene.layout.VBox | |
import javafx.stage.Stage | |
import kotlinfx.* |
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 java.util.LinkedList | |
import java.util.List | |
fun rpn(expression : String) : Double { | |
val expressionElements = expression.split(' ').toLinkedList() | |
val result = foldl(rpn, Stack<Double>(), expressionElements) | |
return result.pop() | |
} | |
private fun foldl<T, U>(f : (T, U) -> T, a : T, l : List<U>) : T { |
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
class Foo<out T>() { | |
var value : T? = null | |
} | |
fun main(args : Array<String>) { | |
val a : Foo<Int> = Foo<Int>() | |
a.value = 5 | |
val b : Foo<Number> = a | |
b.value = 2.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
fun main(args : Array<String>) { | |
val a = arrayList(1) | |
val b = a + a // OK | |
val c = a + arrayList(1) // Compilation error | |
} |
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
// 拡張関数で定義。 | |
// たぶん一番Kotlinらしい書き方 | |
// kotlin friendly | |
fun String.isFourCharacters() = this.size == 4 | |
// static関数として定義。 | |
// Javaっぽい書き方? | |
// like java? | |
//fun isFourCharacters(str : String) = str.isFourCharacters() |
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
for(i in 1..100)println(((a=i%3)?"":"Fizz")+(i%5?(a?i:""):"Buzz")) |
NewerOlder