Computer Science, asked by devupallibabuji57, 11 months ago


2) Write a Java program to find the area of rectangle, triangle,square and circle.​

Answers

Answered by Durgesh12345
1

Answer:

Explanation:

Apply same logic for triangle

Take var as h for height, b for base, and area

Write area as 1/2*h*b

And same program as of square

Attachments:
Answered by rupesh4726
2

Answer:

Explanation:

class OverloadDemo

{

void area(float x)

{

System.out.println("the area of the square is "+Math.pow(x, 2)+" sq units");

}

void area(float x, float y)

{

System.out.println("the area of the rectangle is "+x*y+" sq units");

}

void area(double x)

{

double z = 3.14 * x * x;

System.out.println("the area of the circle is "+z+" sq units");

}

}

class Overload

{

public static void main(String args[])

{

OverloadDemo ob = new OverloadDemo();

ob.area(5);

ob.area(11,12);

ob.area(2.5);

}

}

Output:

$ javac OverloadDemo.java

$ java OverloadDemo

the area of the square is 25.0 sq units

the area of the rectangle is 132.0 sq units

the area of the circle is 19.625 sq units

Similar questions