1.Write a Java program using variables to find the area and Perimeter of a square of side 6 cm [Area= side * side Perimeter = 4*side]
Answers
Area and Perimeter of Square - Java
The area of a square is defined as the product of the two sides of the square. It is also known as squares of sides. The unit of the area is in square units.
The perimeter of a square is equal to the sum of all sides. As we know, all sides of a square are equal so the perimeter is four times the length of any side of a square.
We will use these formulas to write programs to calculate the area and perimeter of a square.
Here's the program:
// Program to calculate the area and perimeter of a square
public class Area_and_Perimeter // Creating class
{
// The Main function
public static void main(String[] args)
{
// Storing side, area and perimeter as int data type
int side = 6, area, perimeter;
// Calculating area of a square
// Area = side * side
area = side * side;
// Calculating perimeter of a square
// Perimeter = 4 * side
perimeter = 4 * side;
// Displaying the result of area of a square
System.out.println("The area of a square is " + area + " square units.");
// Displaying the result of perimeter of a square
System.out.println("The perimeter of a square is " + perimeter + " units.");
}
}
Answer:
write a program to calculate the area and perimeter of a square by using input stream reader class