This example will provide how to print the area and perimeter of a square in Java.
Example:
package octopuscodes.com.demo;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("a: ");
double a = scanner.nextDouble();
double area = a * a;
double perimeter = a * 4;
System.out.println("Area : " + area);
System.out.println("Perimeter : " + perimeter);
}
}
Output:
a: 5
Area : 25.0
Perimeter : 20.0