Rectangle - width = Double.parseDouble(widthStr); //Line 6...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// This Java Program determines the area and // perimeter of a rectangle. / import javax.swing.JOptionPane; i public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; //Line 1 String lengthStr, widthStr, outputStr; //Line 2 lengthStr = JOptionPane.showInputDialog("Enter the length: "); //Line 3 length = Double.parseDouble(lengthStr); //Line 4 widthStr = JOptionPane.showInputDialog("Enter the width: "); //Line 5
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: width = Double.parseDouble(widthStr); //Line 6 area = length * width; //Line 7 perimeter = 2 * (length + width); //Line 8 outputStr = "Length: " + length + "\n" + "Width: " + width + "\n" + "Area: " + area + " square units\n" + "Perimeter: " + perimeter + " units\n"; //Line 9 JOptionPane.showMessageDialog(null, outputStr, "Rectangle", JOptionPane.INFORMATION_MESSAGE); //Line 10 System.exit(0); //Line 11 } }...
View Full Document

Ask a homework question - tutors are online