A
A
Arkady Vinogradov2021-02-04 15:44:10
Kotlin
Arkady Vinogradov, 2021-02-04 15:44:10

Converting Int/String to Char in Kotlin, how to understand?

one)

var number1: Int = 5
    var number2 = number1.toChar()
    println(number2)

Result:
601bec653593c855776339.png
What does this square mean? why does it transform like that

2)
var number1: String = "A"
    var number2 = number1.toChar()
    println(number2)

Результат:  выдает ошибку

Why does it give an error? in theory should be converted to a separate character

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
koperagen, 2021-02-04
@usov-dmitriy

The square means the character with code 5. To convert the digit 5 ​​to the character '5', `Character.forDigit(number1, 10)`
In the second example, the string must not be converted to a single character. Why? And if the string does not consist of one character, then what was this method supposed to do?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question