Given a string, convert the characters of the string into opposite case,i.e. if a character is lower case than convert it into upper case and vice-versa.
Input : geeksForgEeks Output : GEEKSfORGeEKS Input : hello every one Output : HELLO EVERY ONE
ASCII values of alphabets: A – Z = 65 to 90, a – z = 97 to 122
- Take one string of any length and calculate its length.
- Scan string character by character and keep checking the index .
- If character in a index is in lower case, then subtract 32 to convert it in upper case, else add 32 to convert it in lower case
- Print the final string.
Time Complexity: O(n)
Note: This program can alternatively be done using C++ inbuilt functions – Character.toLowerCase(char) and Character.toUpperCase(char).
This article is contributed by Rishabh Jain. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Minimum number of operations to move all uppercase characters before all lower case characters
- Python | Convert a list of characters into a string
- Convert given string so that it holds only distinct characters
- Convert a String into a square matrix grid of characters
- Python | Toggle characters in words having same case
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Min flips of continuous characters to make all characters same in a string
- String with k distinct characters and no same characters adjacent
- String in Switch Case in Java
- Permute a string by changing case
- Toggle case of a string using Bitwise Operators
- Sentence Case of a given Camel cased string
- Lower case to upper case - An interesting fact
- Extract and print words separately from a given Camel Case string
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Transform string str1 into str2 by taking characters from string str3
- Minimal moves to form a string by adding characters or appending string itself