当前位置:网站首页>Basic use of kotlin
Basic use of kotlin
2022-07-04 19:42:00 【AdleyTales】
fun main() {
println("hello world, Hello Kotlin ~")
val result = sum(12, 5)
println(result) // 17
val result2 = sum2(12, 5)
println(result2) // 17
val result3 = sum2(12, 5)
println(result3) // 17
varsFunc("aaaa", "bbbb", "cccc", "dddd", " Ying pengliang ")
println("******------******------******------******------******------******------")
// Define constants and variables val Same as java Of final
val firstname = "adley"
val lastname = "tales"
// String template
val str = "My name is $firstname $lastname !"
println(str)
// NULL Inspection mechanism
// Air safety Add... After the field !! image Java Throw an empty exception , Another field is followed by ? Do not process the return value is null perhaps ?: Short judgment processing
// Type followed by ? Can be empty
var name: String? = "adley"
name = null
println(name)
// Throws a null pointer exception
// var age = name!!.toInt()
// Return... Without processing null
val age2 =name?.toInt()
println(age2) // null
val ages3 = age2?.toInt() ?: -1 // If it's empty , Then for -1
println(ages3) // -1
println(name is String) // false
println(str is String) // true
// Section
for (i in 1..5) {
println(i)
}
for (i in 1..5 step 2) {
println(i)
}
}
// Basic usage
// Package declaration : package com.adleytales.demo
// Function definition
fun sum(x: Int, y: Int): Int {
return x + y
}
// function
fun sum2(x: Int, y: Int): Int = x + y
// function lambda
val sum3: (Int, Int) -> Int = {
x, y -> x + y }
// Variable length parameters vararg
fun varsFunc(vararg str: String) {
for (s in str) {
println(s)
}
}
边栏推荐
- Educational Codeforces Round 22 E. Army Creation
- 反射(一)
- BCG 使用之新建向导效果
- 《工作、消费主义和新穷人》的微信读书笔记
- 1009 product of polynomials (25 points) (PAT class a)
- 牛客小白月赛7 谁是神箭手
- Utilisation de la barre de progression cbcggprogressdlgctrl utilisée par BCG
- Shell programming core technology "four"
- 长城证券开户安全吗 买股票怎么开户
- How to use async Awati asynchronous task processing instead of backgroundworker?
猜你喜欢
随机推荐
在线SQL转Excel(xls/xlsx)工具
Double colon function operator and namespace explanation
TCP两次挥手,你见过吗?那四次握手呢?
BCG 使用之CBCGPProgressDlgCtrl进度条使用
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
反射(一)
BCG 使用之CBCGPProgressDlg进度条使用
Some thoughts on whether the judgment point is located in the contour
kotlin 基本使用
Master the use of auto analyze in data warehouse
abc229 总结(区间最长连续字符 图的联通分量计数)
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
Educational Codeforces Round 22 E. Army Creation
黑马程序员-软件测试--07阶段2-linux和数据库-09-24-linux命令学习步骤,通配符,绝对路径,相对路径,文件和目录常用命令,文件内容相关操作,查看日志文件,ping命令使用,
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Detailed explanation of the binary processing function threshold() of opencv
Educational Codeforces Round 22 E. Army Creation
FPGA时序约束分享01_四大步骤简述
多表操作-内连接查询
欧拉函数









