Convert Case | Convert small letters to capital letters and vice-versa
class ConvertCase {
// ASCII Codes : A-Z = 65-90, a-z = 97-122, 0-9 = 48-57, Enter = 10, Space = 13, Esc = 27
static void convertCase(String str) {
System.out.println("Original String is : " + str);
char[] chars = str.toCharArray();
for(int i = 0; i < chars.length; i++) {
// Convert capital later to small later
if(chars[i] >= 65 && chars[i] <= 90) {
chars[i] += 32; // 97-65 = 32
} else if(chars[i] >= 'a' && chars[i] <= 'z') {
chars[i] -= 32; // 97-65 = 32
}
}
System.out.println("Converted String is : " + new String(chars));
}
public static void main (String[] args) {
String str = "Raghvendra Kumar Mishra";
convertCase(str);
}
}
Comments
Post a Comment