当前位置:网站首页>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 边栏推荐
- Docker configures redis and redis clusters
- 10 minute fitness method reading notes (3/5)
- Correct opening method of redis distributed lock
- About LDA model
- How can labels/legends be added for all chart types in chart. js (chartjs.org)?
- 在家庭智能照明中应用的测距传感芯片4530A
- Redis master-slave configuration and sentinel mode
- Redis's memory elimination mechanism, read this article is enough.
- PIP command reports an error pip is configured with locations that requires tls/ssl problems
- [superhard core] is the core technology of redis
猜你喜欢

Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification

Distributed cache architecture - cache avalanche & penetration & hit rate

Annotation problem and hidden Markov model

Kotlin变量

Read and understand the rendering mechanism and principle of flutter's three trees

C language structure is initialized as a function parameter

Understand redis persistence mechanism in one article

从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks

Add a new cloud disk to Huawei virtual machine

Summary of C language learning problems (VS)
随机推荐
Simply take stock reading notes (1/8)
Master-slave mode of redis cluster
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
GPON other manufacturers' configuration process analysis
How to design an interface?
MySQL trigger
JDBC exercise - query data encapsulated into object return & simple login demo
Third party payment interface design
Anaconda creates a virtual environment and installs pytorch
Solution to order timeout unpaid
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
Redis highly available slice cluster
Introduction to GNN
MySQL stored procedure
Distributed solution - Comprehensive decryption of distributed task scheduling platform -xxljob
Sqoop import and export operation
MySQL constraints
Annotation problem and hidden Markov model
GPS data format conversion [easy to understand]
Time conversion error