Java Code

Share

Java Code

Here’s the Java code:

java
public class RectangleAreaCalculator { public static void main(String[] args) { // Define the length and width of the rectangle double length = 5.0; double width = 3.0; // Calculate the area of the rectangle double area = length * width; // Display the result System.out.println("Rectangle Area Calculator"); System.out.println("Length: " + length); System.out.println("Width: " + width); System.out.println("Area: " + area); } }

In this code:

  • We create a Java class named RectangleAreaCalculator.
  • In the main method (the entry point of the program), we define two variables length and width to represent the dimensions of the rectangle.
  • We calculate the area of the rectangle by multiplying the length and width variables and store the result in the area variable.
  • Finally, we use System.out.println to display the length, width, and calculated area of the rectangle on the console.

To run this Java code:

  1. Make sure you have the Java Development Kit (JDK) installed on your system.

  2. Save the code in a file with a .java extension (e.g., RectangleAreaCalculator.java).

  3. Open a terminal or command prompt and navigate to the directory where the Java file is located.

  4. Compile the code by running the following command:

    bash
    javac RectangleAreaCalculator.java
  5. After successful compilation, run the Java program with this command:

    bash
    java RectangleAreaCalculator

You should see the program output, which will display the rectangle’s dimensions and the calculated area.

This example demonstrates basic Java concepts, including variable declaration, arithmetic operations, and console output. It’s a simple starting point for learning Java programming.

Demo Day 1 Video:

 
You can find more information about Java in this Java Docs Link

 

Conclusion:

Unogeeks is the No.1 Training Institute for Java Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on Java Training here – Java Blogs

You can check out our Best in Class Java Training details here – Java Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *