+ 1
How to use the method parameter in java? Give me an example program in which we can enter desired value of length and breadth
To find perimeter and area of the rectangle with the desired values
1 Réponse
0
class Rectangle
{
import java.util.Scanner;
public class Rectangle
{
int len;
int bre;
//METHOD WITH PARAMETERS
int area(int length,int breadth)
{
len=length;
bre=breadth;
return len*bre;
}
public static void main(String []args)
{
Rectangle rec=new Rectangle();
//SENDING VALUES TO THE METHOD AS ARGUMENTS
int areaofRectangle=rec.area(10,20);
System.out.println("Area ="+areaofRectangle);
//to manually enter the area at RunTime
Scanner sc=new Scanner(System.in);
System.out.println("ENTER LENGTH:");
int l=sc.nextInt();
System.out.println("ENTER BREADTH:");
int b=sc.nextInt();
System.out.println("area of Rectangle is: "+rec.area(l,b));
}
}