当前位置:网站首页>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
边栏推荐
- Get the variable address of structure member in C language
- MySQL storage engine
- ZABBIX agent2 installation
- Flutter2 heavy release supports web and desktop applications
- Kotlin流程控制、循环
- Neural network of PRML reading notes (1)
- Array cyclic shift problem
- Learning JVM garbage collection 06 - memory set and card table (hotspot)
- Introduction to relational model theory
- [hdu 2096] Xiaoming a+b
猜你喜欢
One article tells the latest and complete learning materials of flutter
Master the new features of fluent 2.10
Principle of universal gbase high availability synchronization tool in Nanjing University
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
Third party payment interface design
ZABBIX ODBC database monitoring
[figure neural network] GNN from entry to mastery
ZABBIX customized monitoring disk IO performance
Preliminary exploration of basic knowledge of MySQL
Interviewer: is acid fully guaranteed for redis transactions?
随机推荐
Common commands and basic operations of Apache Phoenix
[hdu 2096] Xiaoming a+b
Flume common commands and basic operations
Distributed cache architecture - cache avalanche & penetration & hit rate
Introduction to GNN
[figure neural network] GNN from entry to mastery
Learn JVM garbage collection 02 - a brief introduction to the reference and recycling method area
Annotation problem and hidden Markov model
ZABBIX ODBC database monitoring
Introduction to relational model theory
Summary of C language learning problems (VS)
Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password
Learn the memory management of JVM 03 - Method area and meta space of JVM
Pytoch loads the initialization V3 pre training model and reports an error
The evolution of mobile cross platform technology
MySQL transaction
Clear neo4j database data
MySQL function
JDBC exercise - query data encapsulated into object return & simple login demo
PXE启动配置及原理