Source of RectangleArea.java


  1: import java.util.Scanner;

  3: /**
  4:  *  This program calculates the area of a rectangle
  5:  *
  6:  *  @author Mark Young (A00000000)
  7:  *  @version 2.3
  8:  */
  9: public class RectangleArea {

 11:     public static void main(String[] args) {
 12:         // Create variables for length, width and area -- and the Scanner
 13:         int length, width, area;
 14:         Scanner kbd = new Scanner(System.in);

 16:         // Tell the user what we're doing
 17:         System.out.println("This program calculates the area of a rectangle.");

 19:         // Get the length and width of the rectangle from the user
 20:         System.out.print("Enter the length and width of the rectangle: ");
 21:         length = kbd.nextInt();
 22:         width = kbd.nextInt();
 23:         kbd.nextLine();

 25:         // Multiply length by width to get the area of the rectangle
 26:         area = length * width;

 28:         // Report dimensions and area to user
 29:         System.out.println("The area of a " + length + "x" + width
 30:             + " rectangle is " + area);
 31:     }

 33: }