当前位置:网站首页>Kotlin variable
Kotlin variable
2022-07-05 12:42:00 【Curious rookie】
One 、 Variable definitions
/*
keyword Variable type
↓ ↓ */
var price: Int = 100; /*
↑ ↑
Variable name A variable's value */In most cases , Variable types can be derived , It can be omitted ; Semicolons at the end are generally omitted ;
Two 、 The type of variable

package com.example.demo
fun main() {
// value type
val int = 1
val long = 1234567L
val double = 13.14
val float = 13.14F
val hexadecimal = 0xAF
val binary = 0b01010101
// toByte()、toShort()、toInt()、toLong()、toFloat()、toDouble()、toChar() Type conversion .
val j = int.toLong();
// Boolean type
val flag1 = true
val flag2 = false
println(flag1 && flag2)
// character
val c: Char = 'A'
// character string
val s = "Hello Kotlin!"
val name = "Kotlin"
print("Hello $name!") //Hello Kotlin!
val array = arrayOf("Java", "Kotlin")
print("Hello ${array.get(1)}!") //Hello Kotlin!
val s2 = """
When our string has a complex format
The original string is very convenient
Because it can do what you see is what you get . """
print(s2)
// Array
val arrayInt = arrayOf(1, 2, 3)
val arrayString = arrayOf("apple", "pear")
println(arrayInt.size) //3
}
3、 ... and 、 Air safety
val i: Double = null // Compiler error Kotlin Developers are forced to define variables , Specifies whether this variable can be null. For possible null The variable of , We need to make a statement , Add a question mark after the variable type “?”
var i: Double = 1.0
var j: Double? = null
i = j // Compiler error
j = i // Compile and pass 边栏推荐
- Full text search of MySQL
- Principle of universal gbase high availability synchronization tool in Nanjing University
- About LDA model
- How can beginners learn flutter efficiently?
- Array cyclic shift problem
- ZABBIX 5.0 - LNMP environment compilation and installation
- MySQL index (1)
- GPS數據格式轉換[通俗易懂]
- Interviewer: is acid fully guaranteed for redis transactions?
- Pytoch through datasets Imagefolder loads datasets directly from files
猜你喜欢

C language structure is initialized as a function parameter

ActiveMQ installation and deployment simple configuration (personal test)

Hexadecimal conversion summary

Take you hand in hand to develop a service monitoring component

Principle of universal gbase high availability synchronization tool in Nanjing University

UNIX socket advanced learning diary - advanced i/o functions

Migrate data from Mysql to neo4j database

Pytoch uses torchnet Classerrormeter in meter

Master the new features of fluent 2.10

在家庭智能照明中应用的测距传感芯片4530A
随机推荐
Redis cluster configuration
PXE startup configuration and principle
Knowledge representation (KR)
只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
Yum only downloads the RPM package of the software to the specified directory without installing it
Solution to order timeout unpaid
GPS数据格式转换[通俗易懂]
Common commands and basic operations of Apache Phoenix
Cypher syntax of neo4j graph database
Redis master-slave configuration and sentinel mode
MySQL function
Pytoch through datasets Imagefolder loads datasets directly from files
Redis highly available sentinel cluster
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
Kotlin变量
The evolution of mobile cross platform technology
Neural network of PRML reading notes (1)
Deep discussion on the decoding of sent protocol
Solve the problem of cache and database double write data consistency
MySQL installation, Windows version