Scala Programming: Convert all the characters in a string to lowercase, uppercase
Write a Scala program to convert all the characters to lowercase, uppercase strings.
Sample Solution:
Scala Code:
object Scala_String {
def main(args: Array[String]): Unit = {
val str = "The Quick BroWn FoX!";
// Convert the above string to all lowercase.
val lowerStr = str.toLowerCase();
val upperStr = str.toUpperCase();
// Display the two strings for comparison.
println("Original String: " + str);
println("String in lowercase: " + lowerStr);
println("String in uppercase: " + upperStr);
}
}
Sample Output:
Original String: The Quick BroWn FoX! String in lowercase: the quick brown fox! String in uppercase: THE QUICK BROWN FOX!
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a Scala program to get a substring of a given string between two specified positions.
Next: Write a Scala program to trim any leading or trailing whitespace from a given string.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics