Page 496 - CA_Blue( J )_Class10
P. 496

System.out.println("Principal"+"\t"+"Rate"+"\t"+"Time"+"\t"+"Amount");
                            System.out.println(p+"\t"+r+"\t"+n+"\t"+a);
                       }
                       void main()
                       {
                            bank b = new bank();
                            b.accept();
                            b.calculate();
                            b.display();
                       }}
                    4.  Define a class to search for a value input by the user from the list of values given below. If it is found display the message
                       "Search successful", otherwise display the message "Search element not found" using Binary search technique.      [15]
                                                                                                 [Understanding Application]
                                                5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
                   Ans.  class binary
                       {
                            double x[]= {5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5};
                            double n;
                            binary(double z)
                            {
                            n=z;
                            }
                            void search()
                            {
                                int f=0, 1 =x.length,m;
                                while(f<=l)
                                {
                                m=(f+l)/2;
                                if(x[m]==n)
                            {
                                System.out.println("Search  Successful");
                                System.exit(0);
                            }
                            if(x[m]<n) f=m+1;
                            if(x[m]>n) l=m-1;
                            }
                            System.out.println(" Search Unsuccessful");
                       }
                    }
                    5.  Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel
                       by immediate next character and every consonant by the previous character. The other characters remain the same.   [15]
                       Example:   Input: #IMAGINATION@2024
                               Output: #JLBFJMBSJPM@2024                                         [Understanding/Application]
                   Ans.  class convert
                       {
                            String s;
                            convert (String z)
                            {
                                s=z;
                            }
                            void convert()
                            {
                                int i' l= s.length();char ch; String ns="";
                                for(i=0;i<l;i++)
                                {
                                ch=s.charAt(i);


                494494  Touchpad Computer Applications-X
   491   492   493   494   495   496   497   498