Syvum Home Page

Home > Discussions > For all activities

Discussion topic: Contributed Answer/Explanation to Q. 3

Viewing replies        View entire discussion

To go to the homepage of this topic, click here.
Home: arnab_javaOriginal MessageReply  
Subject: Contributed Answer/Explanation to Q. 3
   This is the answer to Question-3 (String program).
   import java.io.*;
   import java.util.*;
   class Reverse
   {
       public static void main(String []args)throws IOException
       {
           BufferedReader br=new BufferedReader(new
   InputStreamReader(System.in));
           System.out.println("Enter the sentence");int
   t1,t2,n;
           String
   s=br.readLine(),x="",p="",q="";int k=0;
           int l=s.length();
           for(int i=0;i<l;i++)
           {
               char ch=s.charAt(i);
               if(Character.isUpperCase(ch));
               char chr=Character.toLowerCase(ch);
               x=x+chr;
           }
           StringTokenizer st=new StringTokenizer(x,". ");
           n=st.countTokens();
           String a[]=new String[n],t;
           while(st.hasMoreTokens())
           {
               a[k++]=st.nextToken();
           }
           for(int i=0;i<k;i++)
           {
               for(int j=0;j<(k-1);j++)
               {
                   t1=a[j].length();t2=a[j+1].length();
                   if(t1>t2)
                   {
                       t=a[j];
                       a[j]=a[j+1];
                       a[j+1]=t;
                   }
               }
           }
           p=p+a[0];
           int l1=p.length();
           for(int i=0;i<l1;i++)
           {
               char ch1=p.charAt(i);
               if(i==0)
               ch1=Character.toUpperCase(ch1);
               q=q+ch1;
           }
           System.out.print(q+" ");
           for(int i=1;i<k;i++)
           System.out.print(a[i]+" ");
       }
   }

Posted at: Tue Feb 21 11:59:04 2012 (GMT)

Page 1 of 1
From: arnab_javaReply 1 of 1Reply
Subject: Contributed Answer/Explanation to Q. 3
   This is the answer to Question-3 (String program).
   import java.io.*;
   import java.util.*;
   class Reverse
   {
       public static void main(String []args)throws IOException
       {
           BufferedReader br=new BufferedReader(new
   InputStreamReader(System.in));
           System.out.println("Enter the sentence");int
   t1,t2,n;
           String
   s=br.readLine(),x="",p="",q="";int k=0;
           int l=s.length();
           for(int i=0;i<l;i++)
           {
               char ch=s.charAt(i);
               if(Character.isUpperCase(ch));
               char chr=Character.toLowerCase(ch);
               x=x+chr;
           }
           StringTokenizer st=new StringTokenizer(x,". ");
           n=st.countTokens();
           String a[]=new String[n],t;
           while(st.hasMoreTokens())
           {
               a[k++]=st.nextToken();
           }
           for(int i=0;i<k;i++)
           {
               for(int j=0;j<(k-1);j++)
               {
                   t1=a[j].length();t2=a[j+1].length();
                   if(t1>t2)
                   {
                       t=a[j];
                       a[j]=a[j+1];
                       a[j+1]=t;
                   }
               }
           }
           p=p+a[0];
           int l1=p.length();
           for(int i=0;i<l1;i++)
           {
               char ch1=p.charAt(i);
               if(i==0)
               ch1=Character.toUpperCase(ch1);
               q=q+ch1;
           }
           System.out.print(q+" ");
           for(int i=1;i<k;i++)
           System.out.print(a[i]+" ");
       }
   }

Posted at: Tue Feb 21 12:01:42 2012 (GMT)

Page 1 of 1

To post to this forum, you must be signed in as a Syvum member. Please sign in / register as a member.

Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright