Class Menu_Palin_Count - ICSE_PROJECT                                        1/2
1    import java.io.*;
2    class Menu_Palin_Count
3    {
4        char c;/**class variable declaration and initialization*/
5        int i,t=0;;
6        static String s="",s2="",s3="";
7        void Palin()/**Palin() definition*/
8        {
9            System.out.print("Palindrome words:");
10           for(i=0;i<s.length();i++)
11           {
12               c=s.charAt(i);/**extraction of each character*/
13               if(c==' ')
14               {
15                   if(s3.equalsIgnoreCase(s2))/**checking strings are sam
     e or not*/
16                   {
17                       System.out.print(s2+" ");
18                       t++;
19                   }
20                   s3="";
21                   s2="";
22               }
23               else
24               {
25                   s3=c+s3;/**backward concatenation*/
26                   s2+=c;/**forward concatenation*/
27               }
28           }
29           System.out.print("\nTotal:"+t);
30       }
31
32       void count()/**count() definition*/
33       {
34           char c1,c2;/**variable declaration and initialization*/
35           System.out.print("The words are: ");
36           for(i=0;i<s.length();i++)
37           {
38               c=s.charAt(i);
39               if(c==' ')
40               {
41                   c1=s2.charAt(0);
42                   c2=s2.charAt(s2.length()-1);
43                   if(s3.indexOf(c1)>=0 && s3.indexOf(c2)>=0)
44                   {
45                       System.out.print(s2+" ");
46                       t++;/**counter value increment by 1*/
47                   }
48                   s2="";
49               }
50               else
51                   s2+=c;/**forward concatenation*/
52           }
                                                          21 Nov, 2017 9:49:28 PM
Class Menu_Palin_Count - ICSE_PROJECT (continued)                            2/2
53           System.out.print("\tTotal:"+t);
54       }
55
56       public static void main(String args[])throws IOException/**main fu
     nction definition*/
57       {
58           Menu_Palin_Count ob=new Menu_Palin_Count();/**object creation*
     /
59           BufferedReader br = new BufferedReader(new InputStreamReader(S
     ystem.in));/**object creation*/
60           System.out.println("Enter a choice\n1 for Paindrome word check
     \n2 for vowel position check");
61           int ch=Integer.parseInt(br.readLine());
62           System.out.println("Enter a sentence");
63           s=br.readLine();
64           switch(ch)/**starting of switch block*/
65           {
66               case 1:
67               s+=' ';
68               ob.Palin();/**function calling through object*/
69               break;
70               case 2:
71               s+=' ';
72               s3="AEIOUaeiou";
73               ob.count();/**function calling through object*/
74               break;
75               default:
76               System.out.println("Wrong choice");
77           }/**end of switch block*/
78       }/**end of main method*/
79   }/**end of class Menu_Palin_Count*/
                                                          21 Nov, 2017 9:49:28 PM