Write a Java program to find the perimeter and area of a rectangular field, give
ID: 641242 • Letter: W
Question
Write a Java program to find the perimeter and area of a rectangular field, given its length and width in yards.
Declare variables for length, width, perimeter and area. Use the naming conventions discussed in class.
Initialize the length and width with some particular values (like 12.25 and 5.82)
For finding the perimeter of the rectangle use the formula: perimeter = 2 * (length + width)
For finding the area of the rectangle use the formula: area = length * width
Show the output in the following format:
The perimeter of the rectangle with the length = xx.xx yards and the width = xx.xx yards is xx.xx yards.
The area of the rectangle with the length = xx.xx yards and the width = xx.xx yards is xx.xx square yards.
Explanation / Answer
Comment if you have any doubts
public class PizzaRater
{
static double length=12.25,breadth=5.82,perimeter,area;
public static void main(String[] args)
{
perimeter=2*(length+breadth);
area=length*breadth;
System.out.println("The perimeter of rectanlge with length= "+length+"yards and width= "+breadth+"yards is: "+perimeter+"yards");
System.out.println("The area of rectanlge with length= "+length+"yards and width= "+breadth+"yards is: "+area+"square yards");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.