Page 410 - CA_Blue( J )_Class10
P. 410

while(f<=l) {
                                 m=(f+l)/2;
                                 if(x[m]==n) {
                                     System.out.println("Found the element "+n+" at "+m);
                                     System.exit(0);
                                 }
                                 if(x[m]<n)
                                     f=m+1;
                                 if(x[m]>n)
                                     l=m-1;
                             }
                             System.out.println("Search element not found");
                         }
                     }
                 14.   Define a class to declare a character array of size ten, accept the characters into the array and display the characters with
                    highest and lowest ASCII (American Standard Code for Information Interchange) value.
                     EXAMPLE:                                                                                     [2022]
                     INPUT
                     'R', '2','9','A','N','p','m', 'Q','F'
                     OUTPUT
                     Character with highest ASCII value = 2
                     Character with lowest ASCII value = A
                Ans.  import java.util.Scanner;
                    public class HighLowASCII
                    {
                        public static void main()
                        {
                            char chs[] = new char[10];
                            Scanner sc = new Scanner(System.in);
                            int l = chs.length;
                            System.out.println("Enter 10 characters:");
                            for (int i = 0; i < l; i++)
                            {
                                chs[i] = sc.next().charAt(0);
                            }
                            int largestASCII = (int) chs[0];
                            int smallestASCII = (int) chs[0];
                            for (int i = 1; i < l; i++)
                            {
                                if ((int) chs[i] > largestASCII)
                                {
                                    largestASCII = (int) chs[i];
                                }
                                if ((int) chs[i] < smallestASCII)
                                {
                                    smallestASCII = (int) chs[i];
                                }
                            }
                             System.out.println("Character with lowest ASCII value :" + (char)smallestASCII);
                             System.out.println("Character with highest ASCII value :" + (char)largestASCII);
                        }
                    }
                 15.   Define a class to declare an array of size twenty of double data type, accept the elements into the array and perform the
                    following:
                     • Calculate and print the product of all the elements.


                408408  Touchpad Computer Applications-X
   405   406   407   408   409   410   411   412   413   414   415