Page 282 - CA_Blue( J )_Class9
P. 282

13               System.out.println("Square Root of "+n+" : "+sr); //Displaying Square root
                   14           System.out.println("Cube Root of "+n+" : "+cr); //Displaying Cube root

                   15          }
                   16      }

                  You will get the following output:
                         Enter a number

                         125
                         Square Root of 125.0: 11.180339887498949

                         Cube Root of 125.0: 5.0
                                                         VARIABLE DESCRIPTION
                             NAME              DATATYPE                           DESCRIPTION
                        n                double                 Accepts a Number
                        sr               double                 Square root of the Number
                        cr               double                 Cube root of the Number

                  (v)  Programs based on if else, if else if ladder, nested if, etc.


                   Program 6      Write a program to input a number and print whether it is an even number or an  odd number.

                     1     import java.util.*;                                  //Importing “util” package
                     2     class ifelse                                         //class name

                     3     {
                     4         public static void main()

                     5         {
                     6             Scanner sc=new Scanner(System.in);

                     7             int a;                                       //Declaration of variable
                     8             System.out.print ("Enter a number : ");

                     9             a=sc.nextInt();                              //Accepting number
                   10              if(a%2==0)                                   //Condition checking

                   11                    System.out.println(a + " is an even number");
                   12              else

                   13                    System.out.println(a+ " is not an even number");
                   14          }

                   15      }
                  You will get the following output:

                         Enter a number: 4
                         4 is an even number




                   280    Touchpad Computer Applications-IX
   277   278   279   280   281   282   283   284   285   286   287