kotlin basic syntax (a) .1

I. Introduction:

Kotlin is to enhance the development of an Android voice, although a short time java and will not be replaced, but my door is the need to learn to avoid some transformation,
Android Studio3.0 began officially supported Kotlin, so want to change before use later versions to 3.0
after his syntax similar to the java language we learn, but our grammar is less code than the simple syntax of java, and we have less code, the program also will be a size smaller

Second, the basic type and syntax

  • (A) operating environment:

fun main(){}

  • (B) inside the function and we usually use to have the same function

Int ,Long ,Byte ,Double ,Float ,Boolean ,Short ,Char

  • (C) the basic syntax of a function reference
  • List item

1, an example array traversal
var = intArrayOf Array (1,2,3,4,5,6)
Array.ForEach (:: the println)
2, processing the array to traverse
Fun A (I: Int) {
the println ( "$ { 2} * I ")
}
. 3, traversing a collection of objects
var = ArrayOf Array (". 1 "," 2 ",". 3 ",". 4 ",". 5 ")
Array.ForEach {the println (IT)}
. 4, the while loop
var I = 0;
the while (I <20 is) {
I ++;
Print ( "\ T" + I)}
. 5, for circulation through the collection
var I = 0;
Val ArrayOf = ArrayOf ( "A", "B", "C "," D ")
for (S in ArrayOf) {
I ++
the println (" first "+ i +" is the character string: "+ s)}

  • (Iv) a simple syntax

1, null statement
var otherName: String = null
2, empty judgment
Val lenght = text .lenght?
3, string concatenation
var message = "" Name: "+ name +", Age: "+ age +", gender: "+ sex
4, line
String text = "AAA \ n-" +
"bbbb \ n-" +
"CCC";
. 5, Case statement
var Key Score = // some
var When AAA = (Key) {
7,5 -> "AAA"
4 , 2 -> "bb" 1
-> "c"
the else -> "gone"
}
Here Insert Picture Description
for the first time I do hope you understand

Guess you like

Origin blog.csdn.net/weixin_45095939/article/details/94761656