Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //importing scanner
- public class number2 { //program begins
- public static void main(String[] args) {
- /*
- *Design a program for finding the perimeter and area of each of a set of rectangles
- *Output the sides, area and perimeter of each rectangle
- *Assume that data consists of two sides, side1 and side2.
- *The last data item contains a side1 of zero.
- */
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- int side1, side2, perimeter, area;
- //input statements for the length and width of the rectangle
- System.out.println("Enter length of rectangle: ");
- side1 = input.nextInt();
- System.out.println("Enter width of rectangle: ");
- side2 = input.nextInt();
- //while loop being used as a continuous loop to find the area and perimeter of different rectangle and will end when side1 = 0
- while (side1 != 0) {
- //calculating area and perimeter
- perimeter = (side1 + side2) * 2;
- area = side1 * side2;
- //output statements for length, width, area, and perimeter
- System.out.println("Length: " +side1);
- System.out.println("Width: " +side2);
- System.out.println("Perimeter: " +perimeter);
- System.out.println("Area: " +area);
- //variables being updated within the loop
- System.out.println("Enter length of rectangle: ");
- side1 = input.nextInt();
- System.out.println("Enter width of rectangle: ");
- side2 = input.nextInt();
- } //while loop ends
- }
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement