Area OR Perimeter Solution

Problem

Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.### Input:

  • First line will contain the length (L) of the rectangle.
  • Second line will contain the breadth (B) of the rectangle.

Output:

Output 2 lines.

In the first line print "Area" if area is greater otherwise print "Peri" and if they are equal print "Eq".(Without quotes).

In the second line print the calculated area or perimeter (whichever is greater or anyone if it is equal).

Constraints

  • 1 \leq L \leq 1000
  • 1 \leq B \leq 1000

Sample Input:

1
2

Sample Output:

Peri
6

EXPLANATION:

Area = 1 * 2 = 2

Peri = 2(1 + 2) = 6

Since Perimeter is greater than Area, hence the output is

Peri

6





Program :

 import java.util.*;


public class Main 

{

public static void main(String[] args) 

{

Scanner sc = new Scanner(System.in);

int L = sc.nextInt();

int B = sc.nextInt();

System.out.println(solve(L, B));

sc.close();

}

static String solve(int L, int B) 

{

int area = L * B;

int perimeter = (L + B) * 2;

String comparison;

if (area > perimeter) 

{

comparison = "Area";

else if (area < perimeter) 

{

comparison = "Peri";

else 

{

comparison = "Eq";

}

return String.format("%s\n%d", comparison, Math.max(area, perimeter));

}

}

Post a Comment

0 Comments