Page 252 - computer science (868) class 11
P. 252

s1="";
                                if(c>0)
                                    l=l-c;
                            }
                        }

                        void display()
                        {
                            System.out.println("Original Word:  "+tempwd);
                            System.out.println("Word after removing duplicates:  "+wd);
                        }

                        public static void main()
                        {
                            Scanner sc= new Scanner(System.in);
                            String w;
                            System.out.print("Enter a word: ");
                            w=sc.next();
                            Remove_Duplicates ob=new Remove_Duplicates(w);
                            ob.dup_rev();
                            ob.display();
                        }
                    }
                  6.  Write a program in Java using StringTokenizer to find the shortest and the longest words in the given string.

                Ans.  import java.util.*;
                    class word_Short_Long
                    {
                        public static void main()
                        {
                            Scanner sc= new Scanner(System.in);
                            String str1, s, longstr="", shortstr="";
                            int len=0, lens;
                            System.out.println("Enter the sentence:");
                            str1=sc.nextLine();
                            lens=str1.length();
                            StringTokenizer st=new StringTokenizer(str1);
                            while(st.hasMoreTokens())
                            {
                                s=st.nextToken();
                                if(s.length()>len)
                                {
                                    len=s.length();
                                    longstr=s;
                                }
                                if(s.length()<lens)
                                {
                                    lens=s.length();
                                    shortstr=s;
                                }
                            }
                            System.out.println("Longest Word = "+longstr + " with length="+len);
                            System.out.println("Shortest Word = "+shortstr + " with length="+lens);
                        }
                    }
                  7.  Write a menu-driven program in Java to input a word and print the following pattern as per the user’s choice.
                     Input:  INDIA


                250250  Touchpad Computer Science-XI
   247   248   249   250   251   252   253   254   255   256   257