Computer Science, asked by sahilgavindata, 1 month ago

write a program in java to calculate the area of a square take appropriate variable names and their types in main method parameter as required for input (take as chalange for the brainliest) and give answer properly​

Answers

Answered by MrNulla
0

A square is a simple flat shape in a plane, defined by four points at the four corners. It has four sides with equal length and four corners with right angles.

Method Overloading: Method overloading allows different methods to have the same name, but different signatures where the signature can differ by the number of input parameters or type of input parameters, or both.

In this article, we will learn how to find the area of the square using the method overloading.

Area of the Square

The area of the square is the square of its sides. We can simply calculate the area of the square using the following formula:

Formula:

Area of the Square: A = a2

Here, a is the side of the square.

Below is the implementation of the above approach:

Example 1:

Showing the method overloading of Area() function which has different parameters of square sides of different data-type( float , int , double)

// Java program to find the area of

// the square using Method Overloading

// of parameters with different datatype

// of sides

import ja.va.io.*;

class Square {

// Overloaded Area() function to

// calculate the area of the square

// It takes one double parameter

void Area(double side)

{

System.out.println("Area of the Square: "

+ side * side);

}

// Overloaded Area() function to

// calculate the area of the square

// It takes one float parameter

void Area(float side)

{ System.out.println("Area of the Square: " + side * side) }}

class GFG {

// Driver cøde

public static void main(String[] args)

{

// Creating object of square class

Square obj = new Square();

// Ca.ll.ing function

obj.Area(10);

obj.Area(3.2);

}

}

Output

Area of the Square: 100.0

Area of the Square: 10.240000000000002

Answered by SmilekillerTaeTae
1

Answer:

Area of the Square

The area of the square is the square of its sides. We can simply calculate the area of the square using the following formula:

Area of the Square: A = a2

Here, a is the side of the square.

Attachments:
Similar questions