Computer Science, asked by seemabadhan2016, 3 months ago

write a program in java to initialize 2 values and find area of a rectangle.​

Answers

Answered by deepakkumar9254
1

Algorithm :-

Step 1: Start.

Step 2: Declare three variables of type double l, b and a to store the length, breadth and area of the rectangle.

Step 3: Calculate the area of the rectangle and Print it.

Step 4: End.

Program :-

import java.util.Scanner;  \\importing package

class d  \\class declaration  

{

   public static void main(String args[])

   \\main()method declaration

   {

       System.out.println("Enter the length and breadth of a rectangle");

       double l, b, a;  \\variable description

       Scanner sc=new Scanner(System.in); \\input object creation

       l = sc.nextDouble();

       b = sc.nextDouble();

       a = l*b;

       System.out.println("Area of the rectangle is - " + a);

   }

}  

Output :- in the attachment.

Glossary :-

\begin{array}{| c | c | c |}\cline{1-3} \bf Variable & \bf Type & \bf Description \\ \cline{1-3} l &\sf double & to\:\:store\:\:the\:\:length\:\:of\:\:the\:\:rectangle \\ \cline{1-3} b &\sf double & to\:\:store\:\:the\:\:breadth\:\:of\:\:the\:\:rectangle \\ \cline{1-3} a &\sf double & to\:\:store\:\:the\:\:area\:\:of\:\:the\:\:rectangle\\ \cline{1-3}\end{array}

Attachments:
Similar questions