Home > Software engineering >  Atomic Kotlin, Data Types: Excercise 3
Atomic Kotlin, Data Types: Excercise 3

Time:01-15

thanks for looking and possibly responding

val c1 = 'a'   1
val c2 = 'a'   25
val c3 = 'E' - 2

// 'a'   1
val c1 = 'b'

// 'a'   25
val c2 = ??

// 'E' - 2
val c3 = 'C'

complete noob, why does val c2 = z

I cant understand how 86 translates to 'z'. The unicode table does not give a character that represents 86.

CodePudding user response:

A Kotlin screenshot of unicode table, highlighting

You could also get the decimal value using Char.code

fun main() {
  println('a'.code)
}
97

Run in Kotlin Playground

Therefore, in decimal, 97 25 = 122.

Looking up 122 in the Unicode table reveals that this is the decimal representation of z. You can again use Char.code to get the decimal representation.

fun main() {
  println(('a'   25).code)
  println('a'   25)
}
122
z

Run in Kotlin Playground

  • Related