Page 278 - CA_Blue( J )_Class9
P. 278

INTERNAL ASSESSMENT





                  Marks: 100
                                                                                      21 st   #Problem Solving & Logical Reasoning
                                                                                    Century
                                                                                     Skills  #Creativity & Innovativeness
                  [Important: These programs are indicative only. Teachers and students should use their imagination to create
                  innovative and original assignments.]

                  (i)   Programs using Assignment statements
                                  Write a program to print the area and perimeter of a rectangle whose length is 8 cm and
                    Program 1
                                  breadth is 5 cm.
                     1  class rectangle                                               //Class Name

                     2  {
                     3      public static void main()
                     4      {

                     5        int l,b,a,p;                                            //Variable Declaration
                     6        l=8;

                     7        b=5;
                     8         a=l*b;                                                 // Calculation of area

                     9        p=2*(l+b);                                              //Calculation of perimeter
                    10        System.out.println("Area of a Rectangle : " + a);  //Displaying Area

                    11      System.out.println("Perimeter of a Rectangle : " + p);  //Displaying Perimeter
                    12       }                                                        //Close of main()

                    13  }                                                             //Close of class

                  You will get the following output:
                         Area of a Rectangle : 40
                         Perimeter of a Rectangle : 26

                                                         VARIABLE DESCRIPTION
                             NAME              DATATYPE                           DESCRIPTION
                        l                         int           Length of the rectangle
                        b                         int           Breadth of the rectangle
                        a                         int           Area of a rectangle
                        p                         int           Perimeter of a rectangle












                   276    Touchpad Computer Applications-IX
   273   274   275   276   277   278   279   280   281   282   283