Page 243 - Computer science 868 Class 12
P. 243

8.9 PROGRAMS USING MATHEMATICAL FUNCTIONS
                 Write a Java program to input an integer and print its square root.
                    import java.util.*;
                    class square_root
                    {
                        public static void main(String args[])
                        {
                            int n;
                            double sq;
                            Scanner sc=new Scanner(System.in);
                            System.out.print("Enter an integer number ");
                            n=sc.nextInt();
                            sq=Math.sqrt(n);
                            System.out.println("Square root of " + n + " is " + sq);
                        }
                    }
                 Write a program in Java to input three numbers and display the greatest and the smallest of the two numbers.
                 Hint: Use Math.min() and Math.max()
                 Sample Input: 87, 65, 34
                 Sample Output:

                 Greatest Number = 87
                 Smallest Number = 34
                    import java.util.*;
                    class find_greatest
                    {
                        public static void main(int a,int b, int c)
                        {
                            int g,s;
                            g = Math.max(a, b);
                            g = Math.max(g, c);
                            s = Math.min(a, b);
                            s = Math.min(s, c);
                            System.out.println("Greatest Number = " + g);
                            System.out.println("Smallest Number = " + s);
                        }
                    }
                 8.9.1 Character functions
                 To manipulate the character type data, the Character wrapper class methods are used. The different Character methods
                 are:
                   1.  Character.isLetter(char): This method returns a boolean data type. The output is true if the argument is an alphabet
                    else will return false.
                     System.out.println(Character.isLetter('A'));   // Output: true
                   2. Character.isDigit(char): This method returns true if the argument variable is a digit else will return false.

                      System.out.println(Character.isDigit('1'));   // Output: true
                   3.  Character.isLetterOrDigit(char): This method is used to check whether the parameter passed is a character, digit or
                    not.
                      System.out.println(Character.isLetterOrDigit ('4')); // Output: true





                                                                                                                       241
                                                                                                            Methods    241
   238   239   240   241   242   243   244   245   246   247   248