how to invert characters of String in JAVA | Capital to small and small to capital | TechWithCode

how to invert characters of String in JAVA:
                                                                          This is a java program which inverts the string that means the character which is in capital letter got changed into Small letters and those who are in the small letter are got changed into capital letters.
for example:-

input:- tECHwITHcODE

output:- TechWithCode

Source Code to invert characters of String in JAVA:-

/**
 *
 * @author Deepak Yadav
 */
public class Capital {
    public static void main(String args[]){
        String name = "tECHwITHcODE";
        StringBuilder sb =new StringBuilder();
        for(int i=0;i<name.length();i++){
            char c = name.charAt(i);
            int temp = (int) c;
            if(temp <= 90 && temp >= 65 )
                temp= temp + 32;
                            
            
            else if(temp <= 122 && temp >= 97 )
                temp= temp - 32;
            
            c=(char) temp;
            sb.append(c);
        }
        name=sb.toString();
        System.out.println(name);
    }
}

The output of above program:-


Final Word:-

In this article, We have shown you about the "how to invert characters of String in JAVA".We hope you like it

If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please

Follow us on Instagram
Follow us on Facebook
Subscribe us on Youtube
Follow us on Pinterest

Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.

                               Thank you.

                                        ( नमस्ते )

                                     🙏 


No comments:

Powered by Blogger.