Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 98 - 2617_JSSPS_C-7
P. 98

    You will get the following output:

                  WRITING SOME MORE PROGRAMS

                  Let us write programs using Java's various concepts.
                    Program 3:  Write a program to calculate the area and perimeter of a rectangle.

                  1   public class Calculate {

                  2       public static void main(String args[]) {
                  3           int length, width, area, perimeter;

                  4           length = 5;
                  5           width = 10;

                  6           // Area of rectangle = length * width
                  7           area = length * width;

                  8           // Perimeter of rectangle = 2 * (length + width)
                  9           perimeter = 2 * (length + width);

                  10          System.out.println("Area of the rectangle is: " + area);

                  11          System.out.println("Perimeter of the rectangle is: " + perimeter);
                  12      }

                  13  }

                  You will get the following output:

                            Premium Edition-VII
                     96

| 93 94 95 96 97 98 99 100 101 102 103 |