看第一行代码第三版做的总结
class MainActivity : AppCompatActivity() {
val TAG = "congge"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Log.v(TAG,largerNumber3(5,100).toString())
//Log.v(TAG,getScore("Jim").toString())
loopDemo1()
loopDemo2()
}
private fun largerNumber(num1:Int, num2:Int):Int{
return max(num1,num2);
}
//方法只有一行代码
fun largerNumber2(num1:Int,num2:Int) :Int= max(num1,num2)
//自己写
fun largerNumber3(num1:Int,num2:Int) = if(num1 >num2) num1 else num2
//不带参数的when
fun getScore(name:String) = when{
name.startsWith("Tom") || name== "Jim" -> 86
name == "jack" -> 90
else -> 0
}
//for循环
fun loopDemo1(){
//区间[0,10)
for (i in 0 until 10){
Log.v(TAG,i.toString())
}
}
fun loopDemo2(){
//区间[10,1]
for (i in 10 downTo 1){
Log.v(TAG,i.toString())
}
}
}
网友评论