+ 1

Why don't all the quantities add up and come out separately?

fun main(args: Array<String>) { var arr = arrayOf(1, 3, 5) var x=0 arr.forEach { x+= it *4 println(x) }

20th Jul 2022, 4:42 PM
ANDRES PENA
ANDRES PENA - avatar
3 Answers
+ 4
put println(x) outside after loop..
20th Jul 2022, 4:46 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
Thanks šŸ’–
20th Jul 2022, 4:49 PM
ANDRES PENA
ANDRES PENA - avatar
+ 1
I want the 3 quantities to be added at the end
20th Jul 2022, 4:44 PM
ANDRES PENA
ANDRES PENA - avatar