Page 451 - CA_Blue( J )_Class10
P. 451

System.out.println("Enter the word: ");
                           wd = sc.next();
                           wd=wd.toUpperCase();
                           if(specialword(wd)==1 && palinword(wd)==1 )
                               System.out.println(wd + " is a palindromic word.");
                           if(specialword(wd)==1 && palinword(wd)==0 )
                               System.out.println(wd + " is special word.");
                           if(specialword(wd)==0)
                               System.out.println(wd + " is not a special word.");
                       }
                       }
                    22.  Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for a
                        name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display
                        "Sorry not found!".                                                                         [2016]
                        Seven Wonders: CHICHEN ITZA, CHRIST  THE REDEEMER, TAJ  MAHAL, GREAT  WALL OF  CHINA, MACHU PICCHU, PETRA,
                        COLOSSEUM
                        Locations: MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
                        Examples:
                        Country name: INDIA
                        Output: TAJ MAHAL
                        Country name: USA
                        Output: Sorry not found!

                   Ans. import java.util.*;
                       class sevenWonders{
                       public static void main()
                       {
                          Scanner sc = new Scanner(System.in);
                           String cname;
                           int i,pos=-1;
                           String sw[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJ MAHAL", "GREAT WALL OF
                       CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};
                           String loca[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN", "ITALY"};
                           System.out.print("Country name: ");
                           cname = sc.nextLine();
                           for(i=0; i < sw.length; i++)
                           {
                               if(cname.equalsIgnoreCase(loca[i])) {
                                   pos=i;
                                   break;
                               }
                           }
                           if(pos!=-1)
                               System.out.println(sw[i] + " –" + loca[i]);
                           else
                               System.out.println("Sorry not found!");
                           }
                       }
                    23.  Design a class to overload a function joyString() as follows:                              [2015]
                       (i)   void joyString(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the
                          character argument ch1 with the character argument ch2 in the given string s and prints the new string.
                        Example:
                        INPUT:
                        s = "TECHNALAGY"
                        ch1 = 'A'
                        ch2 = 'O'


                                                                                                                       449
                                                                                                       String Handling  449
   446   447   448   449   450   451   452   453   454   455   456