Q:

Write a Scala program to convert the last 4 characters of a given string in upper case. If the length of the string has less than 4 then uppercase all the characters

0

Write a Scala program to convert the last 4 characters of a given string in upper case. If the length of the string has less than 4 then uppercase all the characters.

All Answers

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

object scala_basic {
    def test(str1: String): String = {
    str1.take(str1.length() - 4) + str1.drop(str1.length() - 4).toUpperCase()
   }
   def main(args: Array[String]): Unit = {
      println("Result: " + test("Scala"));
      println("Result: " + test("Python"));
      println("Result: " + test("abc"));      
    }
  }

Sample Output:

Result: SCALA
Result: PyTHON
Result: ABC

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