w3resource

Java: Convert a given string into lowercase

Java Basic: Exercise-59 with Solution

Write a Java program to convert a string into lowercase.

Pictorial Presentation: String to Lowercase

Java Basic Exercises: Convert a given string into lowercase

Sample Solution:

Java Code:

import java.util.*;
public class Exercise59 {
    public static void main(String[] args) {
        // Create a Scanner object for user input
        Scanner in = new Scanner(System.in);
        System.out.print("Input a String: ");
        
        // Read a string from the user
        String line = in.nextLine();
        
        // Convert the string to lowercase
        line = line.toLowerCase();
        
        // Print the lowercase version of the input string
        System.out.println(line);
    }
}

Sample Output:

Input a String: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.           
the quick brown fox jumps over the lazy dog.

Flowchart:

Flowchart: Java exercises: Convert a given string into lowercase

Java Code Editor:

Previous: Write a Java program to capitalize the first letter of each word in a sentence.
Next: Write a Java program to find the penultimate (next to last) word of a sentence.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/java-exercises/basic/java-basic-exercise-59.php