当前位置:网站首页>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)
}
}
边栏推荐
猜你喜欢
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
MySQL数据库基本操作-DDL | 黑马程序员
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
Pytorch学习(四)
Siemens HMI download prompts lack of panel image solution
Cbcgpprogressdlg progress bar used by BCG
实战模拟│JWT 登录认证
FPGA timing constraint sharing 01_ Brief description of the four steps
TCP两次挥手,你见过吗?那四次握手呢?
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
随机推荐
C语言-入门-基础-语法-流程控制(七)
Educational Codeforces Round 22 E. Army Creation
HDU 1372 & POJ 2243 Knight moves (breadth first search)
长城证券开户安全吗 买股票怎么开户
1002. A+B for Polynomials (25)(PAT甲级)
Online text line fixed length fill tool
Jetpack compose tutorial
“只跑一趟”,小区装维任务主动推荐探索
1007 maximum subsequence sum (25 points) (PAT class a)
添加命名空间声明
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
BCG 使用之新建向导效果
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
Niuke Xiaobai month race 7 F question
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
kotlin 基本数据类型
1008 Elevator(20 分)(PAT甲级)
Explicit random number
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Multi table operation - external connection query