Javatpoint Logo
Javatpoint Logo

Java Program to replace lower-case characters with upper-case and vice-versa

Here, our task is to replace all the lower-case characters in the string to upper-case and upper-case characters to lower-case.

For this purpose, we need to traverse the string and check for each character. If the character is a lower-case character, make it upper-case by using the language-specific built-in method or add 32 to the lower-case character in C to change the ASCII value of the character.

For programming, follow the algorithm given below:


  • STEP 2: DEFINE string str = "Great Power".
  • STEP 3: DEFINE newstr as StringBuffer object .
  • STEP 4: SET i=0. REPEAT STEP 5 to STEP 6 UNTIL i<str.length().
  • STEP 5: IF lower-case character encountered then CONVERT them in upper-case using built-in function
    IF upper-case character encountered then CONVERT them in lower-case characters using built-in function.
  • STEP 6: i=i+1
  • STEP 7: PRINT newstr.
  • STEP 8: END



String after case conversion: gREAT pOWER
Next TopicJava Programs

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA