Computer Science, asked by ritrishnasah, 2 months ago

2. Write a program to input the length and breadth of a rectangle and find its diagonal.
diagonal = length +breadth?​

Answers

Answered by kirtiakruti1421
0

{

e

edit

play_arrow

brightness_4

// JAVA for finding maximum

// p^2/A ratio of rectangle

import java.util.*;

class GFG

{

// function to print length and breadth

static void findLandB(int arr[], int n)

{

// sort the input array

Arrays.sort(arr);

// create array vector of integers occurring in pairs

Vector<Double> arr_pairs = new Vector<Double>();

for (int i = 0; i < n - 1; i++)

{

// push the same pairs

if (arr[i] == arr[i + 1])

{

arr_pairs.add((double) arr[i]);

i++;

}

}

double length = arr_pairs.get(0);

double breadth = arr_pairs.get(1);

double size = arr_pairs.size();

// calculate length and breadth as per requirement

for (int i = 2; i < size; i++)

{

// check for given condition

if ((length / breadth + breadth / length) >

(arr_pairs.get(i) / arr_pairs.get(i - 1) +

arr_pairs.get(i - 1) / arr_pairs.get(i)))

{

length = arr_pairs.get(i);

breadth = arr_pairs.get(i - 1);

}

}

// print the required answer

System.out.print((int)length + ", " + (int)breadth +"\n");

}

// Driver Code

public static void main(String[] args)

{

int arr[] = { 4, 2, 2, 2, 5, 6, 5, 6, 7, 2 };

int n = arr.length;

findLandB(arr, n);

}

}

Answered by raichal1897
7

import java.util*;

public class rectangle

{

public static void main (String Args[])

{

Scanner in =new Scanner (System.in);

int l, b, d;

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

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

l=in.nextInt();

b=in.nextInt();

d=l+b;

System.out.println("Diagonal of the rectangle="+d);

}

}

Similar questions