Write a program to input a string. Convert each alphabet into its opposite case. Print both the strings.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO INPUT  A STRING AND CONVERT EACH OF THE STRING INTO ITS OPPOSITE CASE AND PRINT IT.

import java.util.*;

class U

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

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

        String s = ob.nextLine();

        String st = "";

        for (int i = 0; i < s.length(); i++)

        {

            char ch = s.charAt(i); char c;

            if(ch >= 'A' && ch <= 'Z')

            

                ch += 32;

            

                else if(ch >= 'a' && ch <= 'z')

                

                  ch -= 32;

                  st = st+ch;

                

                

                

            }

            System.out.println("Output");

            System.out.println("Original String = "+s);

            System.out.println("Converted string = "+st);

            }

        }

The above program CODE is compiled and is without any error.

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!


Comments

Popular Posts