ICSE 2022 SEM-2 QUESTION 5 SOLVED

 /* Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other

 * characters should remain the same as before.

 * Example: Input : WelCoMe_2022

 * Output : wELcOmE_2022

 */

import java.util.*;

class QUESTION_5

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        String str;

        System.out.println("Enter a String :");

        str=sc.nextLine();

        int l=str.length();

        for(int i=0;i<l;i++)

        {

            char ch=str.charAt(i);

            if(Character.isLowerCase(ch))

            System.out.print(Character.toUpperCase(ch));

            else if(Character.isUpperCase(ch))

            System.out.print(Character.toLowerCase(ch));

            else

            System.out.print(ch);

        }

    }

}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...