fork download
  1. fun sumOfTwo(array: List<Int>, sum: Int) {
  2. for (i in array.indices) {
  3. for (j in i + 1 until array.count()) {
  4. if (array[i] + array[j] == sum) {
  5. println("${array[i]} + ${array[j]} = $sum")
  6. }
  7. }
  8. }
  9. }
  10.  
  11. fun main() {
  12. val array = listOf(1, 2, 4, 6, 8, 9, 10, 12, 13, 15)
  13. val sum = 18
  14.  
  15. sumOfTwo(array, sum)
  16. }
Success #stdin #stdout 0.1s 46472KB
stdin
Standard input is empty
stdout
6 + 12 = 18
8 + 10 = 18