object Scala_String {
def main(args: Array[String]): Unit = {
var str = "Scala Exercises!";
println("Original String = " + str);
// Get the character at positions 0 and 10.
var index1 = str.charAt(0);
var index2 = str.charAt(10);
var index3 = str.charAt(15);
// Print out the results
println(s"The character at position 0 is ${index1}");
println(s"The character at position 10 is ${index2}");
println(s"The character at position 15 is ${index3}");
println(s"Length of the string: ${str.length}")
}
}
Sample Output:
Original String = Scala Exercises!
The character at position 0 is S
The character at position 10 is c
The character at position 15 is !
Length of the string: 16
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer