-
-
Save pradhuman7d1/690526dad3d1fcf43f4d0c5d4b7b858c to your computer and use it in GitHub Desktop.
Kotlin Strings and Ranges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. What is equals operator? | |
A. equals operator is used to check if two strings are equal. | |
Q. What is the use of string interpolation? | |
A. String interpolation is used to include variables into a string. | |
Q. What is compareTo operator? | |
A. It compares two strings on the basis of its ascii value and provides the output according to the difference of ascii values. | |
Q. What is a range? | |
A. A range is a mathematical sequence between two terminal points like a range from 1 to 20 will contain all the numbers coming in between. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. How to get the number of characters in a String str? | |
a) str.size | |
b) str.size() | |
c) str.length | |
d) str.length() | |
A. c) str.length | |
Q. What will be the output for this snippet? | |
fun main() { | |
val str1 : String = "Hello_World!" | |
val str2 : String = str1.subSequence(0, 5) | |
println(str2) | |
} | |
a) Hello | |
b) Hell | |
c) Hello_ | |
d) Compilation Error | |
A. d) Compilation Error // because .subSequence returns a character sequence so it will cause type mismatch error as we have defined str2 as a string explicitly | |
Q. Which of the following is syntactically correct to print the sum of 2 numbers? | |
a) println("5 + 3 = " 5 + 3) | |
b) println("5 + 3 = $5+3") | |
c) println("5 + 3 = {5 + 3}") | |
d) println("5 + 3 = ${5 + 3}") | |
A. d) println("5 + 3 = ${5 + 3}") | |
Q. Which of these are correct range declarations ? | |
1) 1..50 || 2) 50..1 || 3) 1 downTo 20 || 4) 20 downTo 1 | |
a) 1 and 3 | |
b) 1 and 4 | |
c) 1 and 2 | |
d) 2 and 3 | |
A. b) 1 and 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment