Java Program to change UpperCase character to LowerCase character and vice-versa in a String

This Java Program will change UpperCase character to LowerCase character and LowerCase character to UpperCase For eg,ADfg to adFG and CAt to caT Sa
Admin


This Java Program will change UpperCase character to LowerCase character and LowerCase character to UpperCase For
eg,ADfg to adFG and CAt to caT 

Sample Input 1
ADfg
Sample Output 1
adFG
Sample Input 2
CAt
Sample Output 2
caT
Java
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        toggle(str);
    }
    public static void toggle(String str) 
    {
        for(int i=0;i<str.length();i++)
        {
            int n=str.charAt(i);
            if(n>=65 && n<=90)
            {
                n=n+32;
                char ch=(char)n;
                System.out.print(ch);
                
            }
            else
            {
               n=n-32;
               char ch=(char)n;
               System.out.print(ch);
            }
        }
    }
}

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.