हिंदी

Write a class with the name Perimeter using method overloading that computes the perimeter of a square, a rectangle and a circle. Formula: Perimeter of a square 4*s Perimeter of a rectangle = 2*(1 +b) - Computer Applications

Advertisements
Advertisements

प्रश्न

Write a class with the name Perimeter using method overloading that computes the perimeter of a square, a rectangle and a circle. 

Formula: Perimeter of a square 4*s

Perimeter of a rectangle = 2*(1 +b)

Perimeter of a circle = 2*227*r

कोड लेखन

उत्तर

import java.util.*;
class FQ16{
static void Perimeter(int s)
{System.out.println("Perimeter of the square is " + 4 * s);
}
static void Perimeter(double 1, double b)
{double p = 2 * (1 + b);
System.out.println("Perimeter of the rectangle is " + p);
}

static void Perimeter(double r) 
{double p = 2 * (22.0 / 7) * r;
System.out.println("Perimeter of the circle is " + p);
}
public static void main(String jk[])
{ Scanner ob = new Scanner(System.in);
doubler;
System.out.println("Enter the side of the square");
Perimeter(ob.nextInt()); // METHOD CALL
System.out.println("Enter the length,breadth of the rectangle");
Perimeter(ob.nextDouble(), ob.nextDouble()); // METHOD CALL
System.out.println("Enter the radius of the circle");
r = ob.nextDouble();
Perimeter(r); // METHOD CALL
}}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 5: User - Defined Methods - EXERCISES [पृष्ठ ३३९]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 5 User - Defined Methods
EXERCISES | Q VII. 16. | पृष्ठ ३३९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×
Our website is made possible by ad-free subscriptions or displaying online advertisements to our visitors.
If you don't like ads you can support us by buying an ad-free subscription or please consider supporting us by disabling your ad blocker. Thank you.