Q:

Write a Scala program to create a new String object with the contents of a character array

0

Write a Scala program to create a new String object with the contents of a character array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_String {
  def main(args: Array[String]): Unit = {
    // Character array with data.
    val arr_num = Array('1', '2', '3', '4', '5', '6');

    // Create a String containig the contents of arr_num
    // starting at index 1 for length 2.
    val str = String.copyValueOf(arr_num, 2, 3);

    // Display the results of the new String.
    println("\nThe book contains " + str + " pages.\n");
  }
}

Sample Output:

The book contains 345 pages.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now