title: Rectangle Area and Perimeter
body: <p>I have an assignment that I am having trouble figuring out. </p>
  
  <hr>
  
  <p>Write an application (Rectangle.java) that asks the user to enter the length and the width of a rectangle (both are positive double-precision floating-point numbers), and prints the area and perimeter of the rectangle. When the user enters 7.9 and 4.5, the output of your program should look exactly like the following: </p>
  
  <pre><code>Enter the length and the width of a rectangle: 7.9 4.5
  The area of the rectangle is 35.55.
  The perimeter of the rectangle is 24.80.
  </code></pre>
  
  <hr>
  
  <p>The part I am having trouble with is bringing the output of the perimeter of the rectangle out to two decimal places including the "0."  I have been trying to figure it out for so long.  I know there must be a simple efficient way to do this or it would not be assigned to us as our second Java homework assignment.  If it is to format it as %2d i do not know how to apply that to what i have.  I REALLY appreciate your help!</p>
  
  <p>Here is what i have so far:</p>
  
  <pre><code>import java.util.Scanner;
  public class Rectangle {
  public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.print("Enter the length and the width of a rectangle: ");
  double length = input.nextDouble();
  double width = input.nextDouble();
  double area = (length * width);
  double perimeter = (length * 2 + width * 2);
  System.out.println("The area of the rectangle is " + (int)(area * 100) / 100.0 + ".");
  System.out.println("The perimeter of the rectangle is " + (int)(perimeter * 100) / 100.0 + ".");
  }
  }
  </code></pre>
  
  <p>My Output:</p>
  
  <pre><code>Enter the length and the width of a rectangle: 7.9 4.5
  The area of the rectangle is 35.55.
  The perimeter of the rectangle is 24.8.
  </code></pre>