Computer Science, asked by sonumishra08676, 1 year ago

write a function for evaluating the area of a rectangle having sides a and b. Both sides and the area should be taken as float values.

Answers

Answered by Geekydude121
18
*Make sure the statement : import java.util.*;   is at the beginning of the program code 
public void area ()
{
  Scanner sc=new Scanner(System.in); //Creating an object of Scanner class
  float a,b; //declaring values where a is for length and b for breadth
  float area; // declaring the value for calculating area
  System.out.println("Enter length of rectangle");
  a=sc.nextFloat(); //Taking input 
  System.out.println("Enter breadth");
  b = sc.nextFloat(); //Taking input
  area = a*b; //calculating area of rectangle
  System.out.println("Area of rectangle is "+area+"sq. units");
}
Similar questions