https://try.kotlinlang.org/#/Examples/Hello,%20world!/Simplest%20version/Simplest%20version.kt
/**
* We declare a package-level function main which returns Unit and takes
* an Array of strings as a parameter. Note that semicolons are optional.
*/
fun main(args: Array<String>) {
var c=do1(1);
println("Hello, world!"+c)
var list=listOf(1,2,3,5,7)
for(i in list){
println(i);
}
}
fun do1(a:Int):Int
{
for(i in 1..5)
println(a.toString()+"2");
return a;
}
//类 继承
fun main(args: Array<String>) {
println("Hello, world!")
var tom= student("tom",21);
println(tom.pname+'|'+tom.age);
var jay=teacher("jay",33);
println(jay.name+'|'+jay.age);
}
open class person(var name:String){
public var pname=name;
}
class student(name:String,age:Int):person(name){
public var age=age;
//注释
/*注释
2*/
}
data class teacher(var name:String,val age:Int)
//接口
fun main(args: Array<String>) {
println("Hello, world!")
var ap=mp3Player();
ap.play("beat it");
}
interface play{
fun play(name:String);
}
class mp3Player:play{
override fun play(name:String){
println("playing:"+name);
}
}
From:http://www.cnblogs.com/xuejianxiyang/p/7109520.html