Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main() {
- var prueba = "holita"
- println(prueba)
- prueba = "adios" // to reasign a new variable, not necessary to write "var" again.
- println(prueba)
- prueba = ""
- println(prueba)
- println(prueba.isEmpty()) // if var. is empty => true
- var age: Int = 30 // var var_name: "x" -> x = the type of the variable: int, float, string, etc...
- age = 32
- println(age)
- val nombre = "edgar" // val => variable cant be changed. VAR is a read-only var.
- println(nombre)
- // nombre = "fiorella" ||| will cause error cuz the variable is "val" type
- println(age::class)
- var lower_number_type: Byte = 8 // 8-bit signed int. "Byte" must be written with the first letter in capital form
- var my_short: Short = 16 // 16-bit signed int. idem
- var most_popular_number_type: Int = 32 //. idem
- var huge_number: Long = 64 //. idem
- var decimal_value: Float = 32.00F // 32-bit floating type number. idem
- var larger_decimal: Double = 64.00
- // this value all are object, that means we can call method and properties on them. idem
- println(my_short.toDouble()::class)
- var bigLong: Long = 1_000_000 // for easy reading of big numbers
- println(bigLong)
- var newVar = age.plus(1) // or "age.plus(bigLong)" |||(age=32), its for adding diferente types of variables
- println(newVar)
- var nombre2: String = "Juanito"//we can call dif method and properties on variables
- println(nombre2.length)
- println(nombre2.decapitalize())
- var eg1: String = "holi boli" // "" is for String
- var eg2: Char = 'a' // '' is for char || in kotlin, Char represent 16-bit Unicode character
- println(eg2)
- var frase: String = """
- hello
- welcome to the jungle
- yeah
- """.trimIndent() // trinIndent, eliminate the indentation
- println(frase)
- var variable1: String = "mundo"
- var primer_nombre: String = "javier"
- // $ -> es para concatenar String, tambien dentro de {} se puede poner metodos.
- println("hola $variable1, tu nombre es $primer_nombre y tiene ${primer_nombre.length} caracteres")
- // boolean variables
- var isempty: Boolean = false
- println(isempty)
- println(isempty.not()) // you can negate a variable in boolean
- isempty = "".isBlank() // ".isBlank()" -> a fun that check is the length is 0, if it is then give "true" if not
- // then if give a "false" answer
- println(isempty)
- isempty = "javier".isBlank()
- println(isempty)
- // boolean ends
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement