EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle and the area & circumference of the circle

Rectangle: Area==>l*b
perimeter==>2(l+b)

circle:   Area==>Pi*r(2)
perimeter==>2pi(r)

class Rectangle
{
public static void main(String args[])
{
float l,b,r_area,r_peri,r,c_area,cir;
System.out.println(“enter the length and breadth:”);
Scanner s=new Scanner(System.in);
l=s.nextFloat();
b=s.nextFloat();
System.out.println(“enter the radius”);
r=s.nextFloat();
r_area=l*b;
r_peri=(2*(l+b));
c_area=3.14*r*r;
cir=2*3.14*r;
System.out.println(“Area of Rectangle=”+r_area);
System.out.println(“Perimeter of Rectangle=”+r_peri);
System.out.println(“Area of Circle=”+c_area);
System.out.println(“Circumference of circle=”+cir);
}
}

 

 

 

Similarly,

Here’s a Java program that takes the length and breadth of a rectangle and the radius of a circle as input from the keyboard. It calculates:

  • Area and Perimeter of the Rectangle

  • Area and Circumference of the Circle


✅ Java Code

import java.util.Scanner;

public class ShapesCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Input for Rectangle
System.out.print(“Enter length of the rectangle: “);
double length = sc.nextDouble();

System.out.print(“Enter breadth of the rectangle: “);
double breadth = sc.nextDouble();

// Area and Perimeter of Rectangle
double rectArea = length * breadth;
double rectPerimeter = 2 * (length + breadth);

// Input for Circle
System.out.print(“Enter radius of the circle: “);
double radius = sc.nextDouble();

// Area and Circumference of Circle
double circleArea = Math.PI * radius * radius;
double circleCircumference = 2 * Math.PI * radius;

// Output
System.out.println(“\n— Rectangle —“);
System.out.println(“Area: ” + rectArea);
System.out.println(“Perimeter: ” + rectPerimeter);

System.out.println(“\n— Circle —“);
System.out.println(“Area: ” + circleArea);
System.out.println(“Circumference: ” + circleCircumference);

sc.close();
}
}

Output:

Enter length of the rectangle: 10
Enter breadth of the rectangle: 5
Enter radius of the circle: 7

— Rectangle —
Area: 50.0
Perimeter: 30.0

— Circle —
Area: 153.93804002589985
Circumference: 43.982297150257104

To calculate the area and perimeter of the rectangle and the circle using java

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer