Java Program to replace lower-case characters with upper-case and vice-versa

Java Program to replace lower-case characters with upper-case and vice-versa

Example:

Input: str=BeingCodeExpert
Output: bEINGcODEeXPERT

Approach

Java


public class UpperAndLower {
    public static void main(String[] args) {
        String str = "BeingCodeExpert";
        StringBuffer sb = new StringBuffer(str);
        for (int i = 0; i < sb.length(); i++) {
            if (Character.isUpperCase(sb.charAt(i))) {
                sb.setCharAt(i, Character.toLowerCase(sb.charAt(i)));
            } else {
                sb.setCharAt(i, Character.toUpperCase(sb.charAt(i)));
            }
        }
        System.out.println(sb.toString());

    }
}


No comments:

Post a Comment