By Editorial Staff. Updated on
In this program, we are going to share a Java program to calculate the perimeter of a square. If you are a Java beginner and want to start learning the Java programming, then keep your close attention in this tutorial as I am going to share how to write a Java program to calculate the perimeter of a square with the output.
Copy the below Java program and execute it with the help of Javac compiler. At the end of this program, We have shared the output of this program.
public class JavaProgram
public static void main(String args)
int side, peri, area;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Side Length of Square : ");
side = scan.nextInt();
area = side*side;
peri = 4*side;
System.out.print("Area: " +area);
System.out.print("\nPerimeter: " +peri);
Enter side length of square: 5
Sharing is caring!