java program to find perimeter of square

Solutions on MaxInterview for java program to find perimeter of square by the best coders in the world

showing results for - "java program to find perimeter of square"
Liah
10 Mar 2017
1import java.util.Scanner;
2public class SquarePerimeter
3{
4   public static void main(String[] args)
5   {
6      int side, perimeter;
7      Scanner sc = new Scanner(System.in);
8      System.out.print("Please enter side length of square: ");
9      side = sc.nextInt();
10      perimeter = 4 * side;
11      System.out.print("Perimeter of square is: " + perimeter);
12      sc.close();
13   }
14}
Emmerson
24 Aug 2017
1java program to calculate area of square
2import java.util.Scanner;
3public class FindAreaOfSquare
4{
5   public static void main(String[] args)
6   {
7      Scanner sc = new Scanner(System.in);
8      System.out.println("Please enter side of square: ");
9      double side = sc.nextDouble();
10      // formula area of square = side * side
11      double area = side * side;
12      System.out.println("Area of square is: " + area);
13      sc.close();
14   }
15}