TestingDocs.com
Testing Questions
  • Home
  • Automation
    • Selenium
    • TestNG
  • Tutorials
    • MySQL Tutorials
    • TestLink
    • Maven
    • Git
  • Flowcharts
    • Flowgorithm
    • Raptor

Java Programs

Write a Java program to calculate Area of Rectangle

Java Programs

Problem Statement:

Write a Java program to calculate Area of Rectangle. On this page, we will write a java program to calculate the area of the rectangle. Before writing the program we will analyze the

IPO chart

Input

Length, Width

Process

Area of Rectangle = Length x Width

Output 

Area 

Formula

Area = length*width

Area of Rectangle

Tools Used

We will use the below tools to develop the program. 

  • JDK ( Java Development Kit)
  • Eclipse IDE( Integrated Development Environment) 

Eclipse IDE

Some steps and instructions to create a Java application on Eclipse IDE:

  • Create Java Project in Eclipse

https://www.testingdocs.com/create-a-new-java-project-in-eclipse/

  • Create Java Package in Eclipse

https://www.testingdocs.com/create-java-package-in-eclipse-ide/

  • Create Java Class in Eclipse

https://www.testingdocs.com/create-a-new-java-class-in-a-project/

  • Run Java Project in Eclipse

https://www.testingdocs.com/run-java-project-in-eclipse/


Java Program

The program prompts the user to enter the length and the width. The program uses the Scanner class to read the values from the keyboard. The variables are declared as double data types. 

The program calculates the area as per the mathematical formula and displays the result to the screen. 

Launch IDE and create a Java class.

Enter the program code. 

/**************************************************
 * AreaOfRectangle.java
 * @program : Area of Rectangle
 * @web : www.TestingDocs.com
 * @author : 
 * @version : 1.0
 **************************************************/

import java.util.*;

public class AreaOfRectangle 
{
 public static void main(String arg[ ]) 
 {
 Scanner keyboard = new Scanner(System.in);
 double length, width, areaRectangle;
 System.out.print("Enter Length := ");
 length = keyboard.nextDouble();
 System.out.print("Enter Width := ");
 width = keyboard.nextDouble();
 areaRectangle = length * width;
 System.out.println("Area of Rectangle = "+ areaRectangle);
 }
}

 

Screenshot

Screenshot of the code in the IDE window. 

Sample Output

Save and Run the program from the IDE. Execute some test cases to verify the output of the program. 

Right Click and choose Run as >> Java Application

Output

Enter Length := 5
Enter Width := 3
Area of Rectangle = 15

—

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/


For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Add Two Numbers Flow Chart

Java Programs /

Write a simple java program to add two numbers?

Fahrenheit To Celsius

Java Programs /

Java program to Convert Fahrenheit to Celsius

Java Programs /

Java program for area of triangle

Factorial Java Program using Recursion

Java Programs /

Factorial Java Program using Recursion

Volume of a Cylinder

Java Programs /

Volume of a Cylinder Java Program

‹ Volume of a Cylinder Java Program› Factorial Java Program using Recursion

Recent Posts

  • What are the advantages of PHP?
  • What are the advantages of JavaScript?
  • How to Hide Taskbar on Windows 11
  • How to edit PATH variable on Windows 11?
  • Enable BitLocker Drive Encryption on Windows 11
  • How to lock Windows 11 PC
  • How to Add, Remove Widgets on Windows 11
  • How to Rename PC on Windows 11?
  • How to Shut down Windows 11 PC?
  • How to launch command prompt on Windows 11

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com