Advertisement
advictoriam

Untitled

Nov 27th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that prompts for the height and width of a rectangle
  5.    and prints the area of that rectangle.  
  6.    All variables should be of type double.
  7. */
  8. public class RectArea2
  9. {
  10.    public static void main (String[] args)
  11.    {
  12.       Scanner in = new Scanner(System.in);
  13.      
  14.       // Display prompt for rectangle width
  15.       System.out.print("Please enter the width of the rectangle: ");
  16.  
  17.       // Read width of rectangle
  18.       double width = in.nextDouble();
  19.  
  20.       // Display prompt for rectangle height
  21.       System.out.print("Please enter the height of the rectangle: ");
  22.  
  23.       // Read height of rectangle
  24.      
  25.       double height = in.nextDouble();
  26.  
  27.       // Compute and print result
  28.      
  29.       double area = width * height;
  30.       System.out.println(area);
  31.    }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement