Computer Science, asked by swaminathan17, 7 months ago

write a program to read a string from
the user and convert all uppercase character as lower and vice versa​

Answers

Answered by anushkagupta4648
1

Explanation:

public class changeCase {

public static void main(String[] args) {

String str1="Great Power";

StringBuffer newStr=new StringBuffer(str1);

for(int i = 0; i < str1.length(); i++) {

//Checks for lower case character.

if(Character.isLowerCase(str1.charAt(i))) {

//Convert it into upper case using toUpperCase() function.

plz mark me as a brainliest pls

Answered by Equestriadash
4

string = input("Enter a string: ")

newstr = string.swapcase()

print(newstr, "is the resultant string after swapping cases.")

swapcase() is a string function that converts all upper case characters to lower case and vice-versa.

However, it will not remain permanent. If one wants the new form to be permanent, one must assign the string function to a new variable.

As to the reason why it won't remain permanent, strings are immutable. This means that the characters in it cannot be changed. Upper case characters and lower case characters both are entirely different, having different ASCII values.

Similar questions