Advertisement
acarrunto

1 - variables principales

May 14th, 2022
758
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun main() {
  2.     var prueba = "holita"
  3.     println(prueba)
  4.    
  5.     prueba = "adios" // to reasign a new variable, not necessary to write "var" again.
  6.     println(prueba)
  7.    
  8.     prueba = ""
  9.     println(prueba)
  10.     println(prueba.isEmpty()) // if var. is empty => true
  11.    
  12.     var age: Int = 30 // var var_name: "x" -> x = the type of the variable: int, float, string, etc...
  13.     age = 32
  14.     println(age)
  15.    
  16.     val nombre = "edgar" // val => variable cant be changed. VAR is a read-only var.
  17.     println(nombre)
  18.     // nombre = "fiorella" ||| will cause error cuz the variable is "val" type
  19.    
  20.     println(age::class)
  21.    
  22.     var lower_number_type: Byte = 8 // 8-bit signed int. "Byte" must be written with the first letter in capital form
  23.     var my_short: Short = 16 // 16-bit signed int. idem
  24.     var most_popular_number_type: Int = 32 //. idem
  25.     var huge_number: Long = 64 //. idem
  26.     var decimal_value: Float = 32.00F // 32-bit floating type number.    idem
  27.     var larger_decimal: Double = 64.00  
  28.     // this value all are object, that means we can call method and properties on them.    idem
  29.     println(my_short.toDouble()::class)
  30.    
  31.     var bigLong: Long = 1_000_000 // for easy reading of big numbers
  32.     println(bigLong)
  33.    
  34.     var newVar = age.plus(1) // or "age.plus(bigLong)"  |||(age=32), its for adding diferente types of variables
  35.     println(newVar)
  36.    
  37.     var nombre2: String = "Juanito"//we can call dif method and properties on variables
  38.     println(nombre2.length)
  39.     println(nombre2.decapitalize())
  40.    
  41.     var eg1: String = "holi boli" // "" is for String
  42.     var eg2: Char = 'a'           // '' is for char || in kotlin, Char represent 16-bit Unicode character
  43.     println(eg2)
  44.    
  45.     var frase: String = """
  46.    hello
  47.    welcome to the jungle
  48.    yeah
  49.    """.trimIndent() // trinIndent, eliminate the indentation
  50.     println(frase)
  51.    
  52.     var variable1: String = "mundo"
  53.     var primer_nombre: String = "javier"
  54.     // $ -> es para concatenar String, tambien dentro de {} se puede poner metodos.
  55.     println("hola $variable1, tu nombre es $primer_nombre y tiene ${primer_nombre.length} caracteres")
  56.    
  57.     // boolean variables
  58.     var isempty: Boolean = false
  59.     println(isempty)
  60.     println(isempty.not()) // you can negate a variable in boolean
  61.    
  62.     isempty = "".isBlank() // ".isBlank()" -> a fun that check is the length is 0, if it is then give "true" if not
  63.                             // then if give a "false" answer
  64.     println(isempty)
  65.     isempty = "javier".isBlank()
  66.     println(isempty)
  67.     // boolean ends
  68.    
  69.    
  70. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement