← all problems

Rectangle perimeter and area 🌶️

The program below gives you a rectangle's width and length, and its last two lines (locked) print a variable named rectanglePerimeter and then a variable named rectangleArea. Those two variables don't exist yet. Write the code in the box that declares each one as an int and gives it the correct value, using rectangleWidth and rectangleLength. The perimeter is the distance all the way around the rectangle; the area is the width times the length. Your code will be tested with several different rectangles.

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        int rectangleWidth = 5;
        int rectangleLength = 4;
        // ---- write your code below ----
        System.out.println(rectanglePerimeter);
        System.out.println(rectangleArea);
    }
}