Java Code
Here’s the Java code:
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 variableslength
andwidth
to represent the dimensions of the rectangle. - We calculate the area of the rectangle by multiplying the
length
andwidth
variables and store the result in thearea
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:
-
Make sure you have the Java Development Kit (JDK) installed on your system.
-
Save the code in a file with a
.java
extension (e.g.,RectangleAreaCalculator.java
). -
Open a terminal or command prompt and navigate to the directory where the Java file is located.
-
Compile the code by running the following command:
bashjavac RectangleAreaCalculator.java
-
After successful compilation, run the Java program with this command:
bashjava 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:
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