11. Count the vowels in a string
Required Input:
"hello world"
Expected Output:
Number of vowels: 3
Code In Kotlin
fun main() { val input = "hello world" // Add your code here to count the vowels }
Run Code?
Click Run Button to view compiled output
12. Calculate the area of a rectangle
Required Input:
Length = 5, Breadth = 10
Expected Output:
Area of the rectangle: 50
Code In Kotlin
fun main() { val length = 5 val breadth = 10 // Add your code here to calculate the area }
Run Code?
Click Run Button to view compiled output
13. Swap two numbers using a temporary variable
Required Input:
a = 5, b = 10
Expected Output:
After swapping: a = 10, b = 5
Code In Kotlin
fun main() { var a = 5 var b = 10 // Add your code here to swap the numbers }
Run Code?
Click Run Button to view compiled output
14. Swap two numbers without using a temporary variable
Required Input:
a = 5, b = 10
Expected Output:
After swapping: a = 10, b = 5
Code In Kotlin
fun main() { var a = 5 var b = 10 // Add your code here to swap the numbers }
Run Code?
Click Run Button to view compiled output
15. Check if a number is positive, negative, or zero
Required Input:
-5
Expected Output:
-5 is a negative number
Code In Kotlin
fun main() { val number = -5 // Add your code here to check the type of number }
Run Code?
Click Run Button to view compiled output
16. Find the GCD of two numbers
Required Input:
a = 12, b = 15
Expected Output:
The GCD of 12 and 15 is: 3
Code In Kotlin
fun gcd(a: Int, b: Int): Int { // Add your code here to calculate the GCD } fun main() { val a = 12 val b = 15 println("The GCD of $a and $b is: ${gcd(a, b)}") }
Run Code?
Click Run Button to view compiled output
17. Check if a character is a vowel or consonant
Required Input:
e
Expected Output:
e is a vowel
Code In Kotlin
fun main() { val char = 'e' // Add your code here to check if the character is a vowel or consonant }
Run Code?
Click Run Button to view compiled output
18. Find the square of a number
Required Input:
4
Expected Output:
The square of 4 is: 16
Code In Kotlin
fun square(n: Int): Int { // Add your code here to calculate the square } fun main() { val number = 4 println("The square of $number is: ${square(number)}") }
Run Code?
Click Run Button to view compiled output
19. Find the smallest element in an array
Required Input:
[10, 20, 5, 30]
Expected Output:
The smallest element is: 5
Code In Kotlin
fun main() { val numbers = arrayOf(10, 20, 5, 30) // Add your code here to find the smallest element }
Run Code?
Click Run Button to view compiled output
20. Check if an array contains a specific value
Required Input:
[1, 2, 3, 4, 5], value = 3
Expected Output:
The array contains 3
Code In Kotlin
fun main() { val numbers = arrayOf(1, 2, 3, 4, 5) val valueToCheck = 3 // Add your code here to check if the array contains the value }
Run Code?
Click Run Button to view compiled output