/******************************* MAIN HEADER ********************************** Title: Calculating Program 2 Author: James D. Skrentny, skrentny@cs.wisc.edu copyright 2009-2012 all rights reserved Course: CS 302, Lectures 1 & 2 **************************** 80 columns wide *********************************/ // Code sample showing user input, which makes a program more GENERAL. // Also note the clear prompts and output includes units, which make the // program more USER FRIENDLY. // // This is a better approach than what was done in the CylinderVolume program. import java.util.Scanner; public class RectangleArea { public static void main (String[] args) { Scanner stdIn = new Scanner(System.in); double area, length, width; // get input (include unit of measurement) System.out.print("Enter the width [inches]: "); width = stdIn.nextDouble(); System.out.print("Enter the length [inches]: "); length = stdIn.nextDouble(); // calculate the area area = length * width; // output the result (include unit of measurement) System.out.print("A rectangle of length " + length + " in. and width " + width + " in. has an area of "); System.out.println(area + " in. squared."); } // method main } // class RectangleArea