w3resource logo


Java Programming Exercies

Java String Exercises: Replace all the 'd' characters with 'f' characters

Secondary Nav

Java String : Exercise-24 with Solution

Write a Java program to replace all the 'd' characters with 'f' characters.

Java Code:

public class Exercise24 {
    
   public static void main(String[] args)
    {
        String str = "The quick brown fox jumps over the lazy dog.";

        // Replace all the 'd' characters with 'f' characters.
        String new_str = str.replace('d', 'f');

        // Display the strings for comparison.
        System.out.println("Original string: " + str);
        System.out.println("New String: " + new_str);
    }
}

Output:

Original string: The quick brown fox jumps over the lazy dog.           
New String: The quick brown fox jumps over the lazy fog.

Java Practice online:

public class Exercise24 {
    
   public static void main(String[] args)
    {
        String str = "The quick brown fox jumps over the lazy dog.";

        // Replace all the 'd' characters with 'f' characters.
        String new_str = str.replace('d', 'f');

        // Display the strings for comparison.
        System.out.println("Original string: " + str);
        System.out.println("New String: " + new_str);
    }
}



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program