Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Area Of Rectangle in Java

Area Of Rectangle in Java

Of course! Here's how you can find the Area of a Rectangle in Java:


Formula:

Area=Length×Breadth\text{Area} = \text{Length} \times \text{Breadth}

Example 1: Area of Rectangle (Fixed Values)

public class RectangleArea {    public static void main(String[] args) {        int length = 5;   // Length of rectangle        int breadth = 10; // Breadth of rectangle        int area = length * breadth;  // Area formula        System.out.println("Area of Rectangle is: " + area);    }}

Output:

Area of Rectangle is: 50

Example 2: Area of Rectangle (User Input)

Using Scanner to take input from the user:

import java.util.Scanner;public class RectangleAreaUserInput {    public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);        System.out.print("Enter the length of the rectangle: ");        int length = scanner.nextInt();        System.out.print("Enter the breadth of the rectangle: ");        int breadth = scanner.nextInt();        int area = length * breadth;        System.out.println("Area of Rectangle is: " + area);        scanner.close();    }}

Sample Output:

Enter the length of the rectangle: 7Enter the breadth of the rectangle: 4Area of Rectangle is: 28

Would you also like me to show how to calculate the Perimeter of the Rectangle too? ??
(It's just a small addition!)

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql