当前位置:网站首页>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
- SSRS筛选器的IN运算(即包含于)用法
- Niuke Xiaobai monthly race 7 I new Microsoft Office Word document
- 1011 World Cup betting (20 points) (pat a)
- Shell 編程核心技術《四》
- Online sql to excel (xls/xlsx) tool
- Technologie de base de la programmation Shell IV
- English grammar_ Noun - use
- HDU 1097 A hard puzzle
- “只跑一趟”,小区装维任务主动推荐探索
猜你喜欢

MySQL数据库基本操作-DDL | 黑马程序员

SSRS筛选器的IN运算(即包含于)用法

实战模拟│JWT 登录认证

黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
牛客小白月赛7 谁是神箭手

PointNeXt:通过改进的模型训练和缩放策略审视PointNet++

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

English grammar_ Noun - use

To sort out messy header files, I use include what you use

JVM系列之对象的创建
随机推荐
Online text line fixed length fill tool
Double colon function operator and namespace explanation
一文掌握数仓中auto analyze的使用
The kth largest element in the array
BCG 使用之新建向导效果
Jetpack Compose 教程
Hough transform Hough transform principle
Shell 编程核心技术《一》
明明的随机数
线上数据库迁移的几种方法
Lm10 cosine wave homeopathic grid strategy
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Pointnet/Pointnet++点云数据集处理并训练
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
1005 Spell It Right(20 分)(PAT甲级)
kotlin 基本使用
1002. A+B for Polynomials (25)(PAT甲级)
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
如何使用Async-Awati异步任務處理代替BackgroundWorker?