A string is decoded by converting each first letter of each word in upper case and other in lower case and reversing and printing column wise in the following format write a programme to input any string in mix case separated by single blank space and decode in below format

Sample Input 
Inputted String : ThEquicKBrowNFOxJuMPED
Output :
   d      x     n    k    e 
e         o     w    c    h 
p         F     o    i    T
m               r    u    
u               B    Q 
   J   
            





import java.util.*;
class Decode
{
    String s,s1;
    Decode()
    {
        s="";
        s1="";
    }

    void input(){
        System.out.println("Enter the String");
        Scanner sc=new Scanner(System.in);
        s=sc.nextLine();
    }

    void calculate(){
        boolean check=true;
        String formattedWord="";
        s=s+" ";
        for(int i=0;i< s.length();i++)
        {

            char c=s.charAt(i);
            if(Character.isWhitespace(c)){
                s1=formattedWord+" "+s1; 
                formattedWord="";
                check=true;
            }
            else{
                if(check){
                    formattedWord=Character.toUpperCase(c)+formattedWord;
                    check=false;
                }
                else{
                    formattedWord=Character.toLowerCase(c)+formattedWord;
                } 
            }
        }
    }

    void arrange(){
        int counter=0;
        String[] words = s1.split(" ");
        int maxLength = 0;

        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if (word.length() > maxLength) {
                maxLength = word.length();
            }
        }

        for(int i=0;i< maxLength;i++)
        {
            for(int j=0;j< words.length;j++)
            {
                String word=words[j];

                if(i< word.length())
                {
                    System.out.print(word.charAt(i));

                }else{
                    System.out.print(" ");
                }
                System.out.print(" ");
            }
            System.out.println();
        }

    }

    public static void main(String args[])
    {
        Decode obj=new Decode();
        obj.input();
        obj.calculate();
        obj.arrange();
    }
}


     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com