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:

Algorithm

  • STEP 1: START
  • 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
    else
    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

Program:

Output:

String after case conversion: gREAT pOWER
Next TopicJava Programs





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA