Sunday, September 10, 2017

Functions(static void )

Challenge: Write a program that asks the user for the lengths of a rectangle’s sides. Then print the area and the perimeter of the rectangle.


import java.util.*;
class lab2_4{

public static void main(String[]args)
System.out.println("Please: enter the length and width of your rectangle");
Scanner in=new Scanner(;
System.out.println("Enter width:");
double width=in.nextDouble();
System.out.println("Enter length:");
double length=in.nextDouble();


public static void areaCalculator(double w, double l)
double aCalculator= w*l;
System.out.println("The rectangle's area is: "+ aCalculator);
public static void perimeterCalculator(double wp,double lp)
double pCalculator= (2*wp)+(2*lp);
System.out.println("The rectangle's perimeter is: "+ pCalculator);

No comments:

Post a Comment