Write a Java Program to accept the length and breadth of a rectangle and find its perimeter (output also plzzzz)
Answers
// Java program to find the perimeter of a rectangle
import java.util.Scanner;
public class Demo {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the length & width of the rectangle::\n");
// Reading data using readLine
float l = in.nextFloat();
float w = in.nextFloat();
float p;
/* Calculate perimeter of rectangle */
p = 2 * (l + w);
System.out.print("\n");
System.out.println("The Perimeter of rectangle = " + p + " units");
}
}
output:
Output:
$ javac Area_Perimeter .java
$ java Area_Perimeter
Enter length of rectangle:4
Enter breadth of rectangle:5
Perimeter of rectangle:18
Area of rectangle:20
int, java.util.Scanner;
class PerimeterOfRectangle
{
public static void main(String [])
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the length of the Rectangle:");
double l = s.nextDouble();
System.out.println("Enter the width of the Rectangle:");
double b= s.nextDouble();
double perimeter=2*(l+b);
System.out.println("Orignal perimeter: " + perimeter);
}
}
int, java.util.Scanner;
class PerimeterOfRectangle
{
public static void main(String [])
{
Scanner s= new Scanner(System.in);
System.out.println("8:");
double l = s.nextDouble();
System.out.println("6:");
double b= s.nextDouble();
double perimeter=2*(8+6);
System.out.println(" 28" );
}
}
- Length = 8
- Breadth = 6
Perimetere = 2 ( l + b )
= 2 ( 8 + 6)
= 2 × 14
= 28
Availble on Brainly web
______________________________________