Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jooinfoo.logic
- object Learn {
- @JvmStatic
- fun main(args: Array<String>) {
- val numbers1 = arrayOf(1,12,31,5,3,23,4,5,22)
- val numbers2 = arrayOf(98,12,42,13,13,56,100,99)
- findSecondMax(numbers1)
- }
- private fun findSecondMax(numbers: Array<Int>) {
- var max1 = numbers[0]
- var max2 = numbers[1]
- for (i in 0 until numbers.size) {
- if (max1 < numbers[i]) {
- max2 = max1
- max1 = numbers[i]
- } else if (max2 < numbers[i]) max2 = numbers[i]
- }
- println("Second max number is $max2")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement