Write a program of converting the lower text into upper and vice versa. Please reply soon
__________
[Examination]
Answers
Answer:
An array of char type s[100] is declared which will store the entered string by the user. Then for loop is used to convert the string into lower case string and if block is used to checkthat if characters are in uppercase then, convert them in lowercase by adding 32 to their ASCII value.
Answer:
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
newStr.setCharAt(i, Character.toUpperCase(str1.charAt(i)));
}
//Checks for upper case character
else if(Character.isUpperCase(str1.charAt(i))) {
//Convert it into upper case using toLowerCase() function
newStr.setCharAt(i, Character.toLowerCase(str1.charAt(i)));
}
}
System.out.println("String after case conversion : " + newStr);
}
}