Computer Science, asked by yadunandan, 1 year ago

Write a program in java to input length and breadth of a rectangle. Calculate and display the area,perimeter or diagonal of rectangle as per user choice.

Answers

Answered by abhi220
128
import java.util.*;
public class rectangle
{
public static void main()
{
Scanner sc =new Scanner (System.in);
System.out.println("enter length,breadth of rectangle");
double l=sc.nextDouble();
double b=sc.nextDouble ();
System.out.println ("enter choice");
int ch=sc. nextInt();
switch(ch)
{
case1:
double a;
a=l*b;
System.out.println ("area="+a);
break;
}
case 2:
{
double p;
p=2*(l+b);
System. out.println ("perimeter="+p);
break;
}
case 3:
{
double d=Math.sqrt(l*l+b*b);
System. out.println ("diagonal="+d);
break;
}
default :
{
System.out.println ("wrong choice");
}
}
}
Answered by IndieLov
27
Here's a JavaScript program: (NodeJS 6):

//Code Starts
function Rectangle (length, breadth) {
  this.Area = length*breadth;
  this.Perimeter = 2*length + 2*breadth;
  this.Diagonal = Math.sqrt((length**2)+(breadth**2))
}
// Code Ends
Similar questions