Answer to Question #251576 in Java | JSP | JSF for AYESHA

Question #251576

Write a Java program that calculates area and perimeter of square in a function. Name Calculate Area and Calculate Perimeter respectively. The values that will be passed to the functions will be first input by user.


1
Expert's answer
2021-10-17T01:45:37-0400

Source code

import java.util.Scanner;
public class Main
{
    static double calculatesArea(double s){
        return (s*s);
    }
    static double CalculatePerimeter(double s){
        return (4*s);
    }
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		double side;
		System.out.println("Enter the length of the sides of the square: ");
		side=in.nextDouble();
		System.out.println("Area of the square: "+calculatesArea(side));
		System.out.println("Perimeter of the square: "+CalculatePerimeter(side));
	}
}

Output


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS