Write a program to Given string Convert Uppercase to Lowercase


The code is correct and will convert all uppercase characters in the given string to lowercase. The code works by iterating over each character in the string and checking if it is an uppercase character using the Character.isUpperCase() method. If the character is uppercase, it is replaced with its lowercase equivalent using the Character.toLowerCase() method.

The convert_lowercase() method takes a StringBuffer object as input and modifies it in-place. The modified string with all lowercase characters is then printed using System.out.println().

Source Code

class String_LowerCase
{
	static void convert_lowercase(StringBuffer str)
	{
		int len = str.length();
		for (int i = 0; i < len; i++) {
			Character c = str.charAt(i);
			if (Character.isUpperCase(c))
				str.replace(i, i + 1,Character.toLowerCase(c) + "");
		}
	}
 
	public static void main(String[] args)
	{
		StringBuffer str = new StringBuffer("Tutor Joes Computer Education");
		System.out.println("Given String : "+str);
		convert_lowercase(str);
		System.out.println("Convert LowerCase : "+str);
	}
}

Output

Given String : Tutor Joes Computer Education
Convert LowerCase : tutor joes computer education

Example Programs