Write a program in java to accept the perimeter of a square and calculate its side.
Answers
import java.util.*;
public class Side
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
float p, s;
System.out.println("Enter the perimeter of the square");
p= in.nextFloat();
s=p/4;
System.out.println("The side of the square is"+s);
}
}
import java.util.Scanner;
class PerimeterOfSquare
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the side of the square:");
double a= s.nextDouble();
double perimeter=4*a;
System.out.println("perimeter of Square is: " + perimeter);
}
}
Using Command Line Arguments
import java.util.Scanner;
class PerimeterOfSquare1
{
public static void main(String args[])
{
double a= Double.parseDouble(args[0]);
double perimeter=4*a;
System.out.println("perimeter of Square is: " + perimeter);
}
}