Write a program to find top two maximum numbers in the given array. You should not use any sorting functions.
You should iterate the array only once. You should not use any kind of collections in java.
Kotlin program to find top two maximum numbers in a array
fun printTwoMaxNumbers(nums: IntArray) {
var maxOne = 0
var maxTwo = 0
for (n in nums) {
if (maxOne < n) {
maxTwo = maxOne
maxOne = n
} else if (maxTwo < n) {
maxTwo = n
}
}
println("First Max Number: $maxOne")
println("Second Max Number: $maxTwo")
}
fun main(a: Array<String>) {
val num = intArrayOf(5, 34, 78, 2, 45, 1, 99, 23)
printTwoMaxNumbers(num)
}
Output
First Max Number: 99
Second Max Number: 78
Write a program to find the given number is Armstrong number or not
Check whether two strings are anagram of each other
Write a kotlin program to find common elements between two arrays
Write a program to find out duplicate characters in a string
Write a kotlin Program to find Factorial of a Given Number
Write a kotlin program to reverse a string using recursive methods
Write a program to check the given number is a prime number or not
Check if two given strings are isomorphic to each other
Kth Largest Element in an array with kotlin
Write a kotlin program to find perfect number or not
A Program to check if strings are rotations of each other or not
Write a Kotlin Program to Remove Common Characters From Given Strings
Kotlin program to reverse a given number
Write a kotlin program to reverse a string using recursive methods
Write a kotlin program to reverse a string using recursive methods
Reverse Words in a String using kotlin
How to swap two numbers without using temporary variable
Write a program to find top two maximum numbers in a array
| |||||
Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.