Practice 50 Kotlin Basic Coding Questions, TechnoVlogs

Practice 50 Kotlin Basic Coding Questions


Q1. Write a Kotlin program to print "Hello, World!"
  Input: (None)
  Expected Output: Hello, World!

Q2. Write a Kotlin program to calculate the sum of two numbers.
  Input: a = 5, b = 10
  Expected Output: Sum is: 15

Q3. Write a Kotlin program to find the largest of three numbers.
  Input: a = 7, b = 12, c = 9
  Expected Output: Largest number is: 12

Q4. Write a Kotlin program to check if a number is even or odd.
  Input: num = 4
  Expected Output: Even

Q5. Write a Kotlin program to find the factorial of a number.
  Input: num = 5
  Expected Output: Factorial is: 120

Q6. Write a Kotlin program to check if a number is positive, negative, or zero.
  Input: num = -8
  Expected Output: Negative

Q7. Write a Kotlin program to print the multiplication table of a number.
  Input: num = 3
  Expected Output:    
    3 x 1 = 3
    3 x 2 = 6
    3 x 3 = 9
    ...

Q8. Write a Kotlin program to find the average of a list of numbers.
  Input: numbers = [2, 4, 6, 8]
  Expected Output: Average is: 5.0

Q9. Write a Kotlin program to reverse a string.
  Input: str = "hello"
  Expected Output: olleh

Q10. Write a Kotlin program to find the length of a string.
   Input: str = "Kotlin"
   Expected Output: Length is: 6

Q11. Write a Kotlin program to check if a string is a palindrome.
   Input: str = "madam"
   Expected Output: Palindrome

Q12. Write a Kotlin program to count the number of vowels in a string.
   Input: str = "Kotlin"
   Expected Output: Vowel count is: 2

Q13. Write a Kotlin program to print the Fibonacci series up to a given number.
   Input: num = 10
   Expected Output: 0 1 1 2 3 5 8

Q14. Write a Kotlin program to check if a year is a leap year.
   Input: year = 2020
   Expected Output: Leap year

Q15. Write a Kotlin program to swap two numbers.
   Input: a = 5, b = 10
   Expected Output: a = 10, b = 5

Q16. Write a Kotlin program to find the greatest common divisor (GCD) of two numbers.
   Input: a = 56, b = 98
   Expected Output: GCD is: 14

Q17. Write a Kotlin program to check if a number is prime.
   Input: num = 7
   Expected Output: Prime

Q18. Write a Kotlin program to print the multiplication of two matrices.
   Input: matrix1 = [[1, 2], [3, 4]], matrix2 = [[5, 6], [7, 8]]
   Expected Output: [[19, 22], [43, 50]]

Q19. Write a Kotlin program to find the sum of elements in an array.
   Input: arr = [1, 2, 3, 4, 5]
   Expected Output: Sum is: 15

Q20. Write a Kotlin program to find the minimum element in an array.
   Input: arr = [4, 2, 8, 1, 9]
   Expected Output: Minimum element is: 1

Q21. Write a Kotlin program to convert Celsius to Fahrenheit.
   Input: celsius = 25
   Expected Output: Fahrenheit: 77.0

Q22. Write a Kotlin program to check if a number is divisible by 5.
   Input: num = 10
   Expected Output: Divisible by 5

Q23. Write a Kotlin program to print the even numbers between 1 and 20.
   Input: (None)
   Expected Output: 2 4 6 8 10 12 14 16 18 20

Q24. Write a Kotlin program to find the square of a number.
   Input: num = 4
   Expected Output: Square is: 16

Q25. Write a Kotlin program to find the cube of a number.
   Input: num = 3
   Expected Output: Cube is: 27

Q26. Write a Kotlin program to check if a number is a perfect square.
   Input: num = 16
   Expected Output: Perfect square

Q27. Write a Kotlin program to find the power of a number.
   Input: base = 2, exponent = 3
   Expected Output: Power is: 8

Q28. Write a Kotlin program to print the first N natural numbers.
   Input: N = 5
   Expected Output: 1 2 3 4 5

Q29. Write a Kotlin program to calculate the sum of digits of a number.
   Input: num = 123
   Expected Output: Sum of digits is: 6

Q30. Write a Kotlin program to check if a number is a perfect number.
   Input: num = 28
   Expected Output: Perfect number

Q31. Write a Kotlin program to print a triangle pattern.
   Input: n = 5
   Expected Output:
     *
     **
     ***
     ****
     *****

Q32. Write a Kotlin program to find the second largest number in an array.
   Input: arr = [4, 6, 9, 1, 3]
   Expected Output: Second largest number is: 6

Q33. Write a Kotlin program to convert a string to uppercase.
   Input: str = "kotlin"
   Expected Output: KOTLIN

Q34. Write a Kotlin program to convert a string to lowercase.
   Input: str = "KOTLIN"
   Expected Output: kotlin

Q35. Write a Kotlin program to print a pyramid pattern.
   Input: n = 4
   Expected Output:
       *
      ***
     *****
    *******

Q36. Write a Kotlin program to find the number of occurrences of a character in a string.
   Input: str = "Kotlin", char = 'o'
   Expected Output: Occurrences: 1

Q37. Write a Kotlin program to check if a string contains a substring.
   Input: str = "Kotlin", substring = "tin"
   Expected Output: Contains substring

Q38. Write a Kotlin program to check if a number is an Armstrong number.
   Input: num = 153
   Expected Output: Armstrong number

Q39. Write a Kotlin program to remove all white spaces from a string.
   Input: str = "Hello World"
   Expected Output: HelloWorld

Q40. Write a Kotlin program to find the sum of the diagonal elements of a matrix.
   Input: matrix = [[1, 2], [3, 4]]
   Expected Output: Sum of diagonal elements is: 5

Q41. Write a Kotlin program to check if a number is a palindrome number.
   Input: num = 121
   Expected Output: Palindrome number

Q42. Write a Kotlin program to find the reverse of an array.
   Input: arr = [1, 2, 3, 4]
   Expected Output: [4, 3, 2, 1]

Q43. Write a Kotlin program to find the sum of even numbers in an array.
   Input: arr = [1, 2, 3, 4, 5]
   Expected Output: Sum of even numbers is: 6

Q44. Write a Kotlin program to check if a string starts with a specific character.
   Input: str = "Kotlin", char = 'K'
   Expected Output: Starts with 'K'

Q45. Write a Kotlin program to find the smallest element in a list.
   Input: list = [3, 5, 1, 9]
   Expected Output: Smallest element is: 1

Q46. Write a Kotlin program to concatenate two strings.
   Input: str1 = "Hello", str2 = "World"
   Expected Output: HelloWorld

Q47. Write a Kotlin program to find the sum of odd numbers in an array.
   Input: arr = [1, 2, 3, 4, 5]
   Expected Output: Sum of odd numbers is: 9

Q48. Write a Kotlin program to sort an array in ascending order.
   Input: arr = [4, 2, 9, 1, 5]
   Expected Output: [1, 2, 4, 5, 9]

Q49. Write a Kotlin program to check if a string ends with a specific suffix.
   Input: str = "Kotlin", suffix = "lin"
   Expected Output: Ends with 'lin'

Q50. Write a Kotlin program to create a simple calculator that performs addition, subtraction, multiplication, and division.
   Input: a = 10, b = 5
   Expected Output
   Addition: 15
   Subtraction: 5
   Multiplication: 50
   Division: 2.0

Share on Social Media