I am making a Math quiz and want to perform Addition operation "with carrying". I want to get a digit at specific index but cannot find any method for it. I am currently doing it with convert Int into toString() but some times it doesn't gives correct value. My code:
fun main(args: Array<String>) {
var a = (100..999).random()
var b = (1..9).random().toString()
var temp = a.toString().get(2)
var temp1 = (temp+b)
var length = temp1.toString().length
println(a)
println(b)
println("last index: "+temp)
println("temp1: "+temp1)
println("length: "+length)
}
Output:
length is greater then 1
a : 771
b : 6
last index : 1
Addition : 16
length : 2
You can see the result. When i add two digits it's doesn't gives the correct value. So is there any method to extract any digit at specific index.