perimeter of square in java code example
Example 1: Java program to find perimeter of square
import java.util.Scanner;
public class SquarePerimeter
{
public static void main(String[] args)
{
int side, perimeter;
Scanner sc = new Scanner(System.in);
System.out.print("Please enter side length of square: ");
side = sc.nextInt();
perimeter = 4 * side;
System.out.print("Perimeter of square is: " + perimeter);
sc.close();
}
}
Example 2: Java program to find perimeter of square
java program to calculate area of square
import java.util.Scanner;
public class FindAreaOfSquare
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter side of square: ");
double side = sc.nextDouble();
double area = side * side;
System.out.println("Area of square is: " + area);
sc.close();
}
}