[Android learning] Kotlin language basic knowledge learning

1. Initial kotlin

2. kotlin writer

  1. understand the IDEA

https://blog.csdn.net/rbx508780/article/details/126647849

  1. Online website

http://try.kotlinlang.org

3.Android studio

https://blog.csdn.net/beita08/article/details/118885114

3. Variables and functions

  1. variable

Format: variable name: type = variable value

Two keywords
1. val keyword: immutable variable
2. var keyword: variable variable
*** The type does not need to be indicated, it can be deduced
or the type can be explicitly marked.
val a = 10
var b = 10
val c : Int = 10

2. Function

Format: fun function name (parameter name 1: parameter type, parameter name 2: parameter type): return value type {function body}

The parameter and return value types can be missing

1) Keyword fun

All function names need to be preceded by the keyword: fun

The main function is the entry point of the program. Each program can only have one main function.

2) Keyword return

Indicates returning the value of a function

Example:

package com.example.helloworld

fun main() {
    println("Hello world.This is my first time to learn Kotlin Language!")
    println("c="+ addFun(2,3))
}

//自定义一个相加的函数
fun addFun(a:Int,b:Int):Int{
    val c = a+b
    return c
}

Guess you like

Origin blog.csdn.net/qq_45769063/article/details/129052507