Write a program to Given string Convert Lowercase to Uppercase


This program takes a StringBuffer as input and converts all lowercase characters to uppercase characters. The method convert_uppercase() takes the StringBuffer as input and uses a for loop to iterate through each character of the string. If the character is lowercase, the Character.toUpperCase() method is used to convert it to uppercase, and the StringBuffer.replace() method is used to replace the lowercase character with the uppercase character. Finally, the modified StringBuffer is printed.

Source Code

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

Output

Given String : Tutor Joes Computer Education
Convert UpperCase : TUTOR JOES COMPUTER EDUCATION

Example Programs