Number data types

Number data types accept whole numbers and do not support fractions. Kotlin provides four different types of number variables—Integer, Long, Byte, and Short. These data types can be declared with and without type annotation. It can also be easily declared with the following syntax:

var myInt : Int =10  // For Integer variable
var myInt = 10
var myLong : Long = 11 // For Long Variable
var myShort : Short = 11 // For Short Variable
var myByte : Byte = -100 For byte variable

MAX_VALUE and MIN_VALUE can be used to find the capacity of each variable.

See the following example: 

fun main(args: Array<String>) {
println("max integer " + Integer.MAX_VALUE)
println("min integer " + Integer.MIN_VALUE)
}

The following output shows the maximum and minimum value an integer can hold:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.235.79