Computer Science, asked by yeshukiraah, 3 months ago

Write a program to calculate the following expressions using method.

(i) area of square = a2

(ii) area of rectangle = Ixb

(iii) area of circle = pi.r2​

Answers

Answered by himanshu2006vps
1

import java.util.*;

public class Calculate

{

int sq, rec;

double cir;

void square (int a)

{

sq= a*a;

System.out.println("Area of square="+sq);

}

void rectangle ( int l, int b)

{

rec= l*b;

System.out.println("Area of rectangle="+rec);

}

void circle ( double r)

{

cir= (22/7.0)*r*r;

System.out.println("Area of circle="+cir);

}

public static void main(String args[])

{

Scanner in= new Scanner (System.in);

int s,a,c;

double d;

System.out.println("Enter the side of a cube, length and breadth of a rectangle, radius of a circle");

s= in.nextInt();

a= in.nextInt();

c= in.nextInt();

d= in.nextDouble();

Calculate ob= new Calculate ();

ob.square(s);

ob.rectangle(a,c);

ob.circle(d);

}

}

Hope this helps dear

Similar questions