Computer Science, asked by adfrt, 1 year ago

Write a program in java to accept the perimeter of a square and calculate its side.

Answers

Answered by Anonymous
2

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);

}

}

Answered by jack6778
3

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);

}

}

Similar questions