- Version
- Download 32
- File Size 3.19 KB
- File Count 1
- Create Date May 12, 2016
- Last Updated May 12, 2016
Area of Rectangle Solver in Java
Area of Rectangle Solver in Java
It is a very simple program intended for beginners who wants to learn java programming language. The program will computer for the area of a rectangle, the user will be ask to enter the length and the width of the rectangle then the program will display the result. The program is written in gui and console version.
Source code:
import javax.swing.*;
public class AreaRectangleGUI
{
public static void main(String args[]) {
String input1, input2;
double length;
double width ;
double result=0;
String cont="n";
do
{
input1 = JOptionPane.showInputDialog(null,"Enter length: ");
input2 = JOptionPane.showInputDialog(null,"Enter width: " );
length=Double.parseDouble(input1);
width=Double.parseDouble(input2);
result = length * width ;
JOptionPane.showMessageDialog(null,"area is: " + result );
cont = JOptionPane.showInputDialog(null, "Again y for yes, n for no");
}while (cont.matches("y"));
JOptionPane.showMessageDialog(null,"Program Closing");
}
}