-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathreplace_case.java
22 lines (19 loc) · 950 Bytes
/
replace_case.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
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);
}
}