Write a java program that asks the user to enter the length and breadth of rectangle and decide if it square or not square?
Answers
Answered by
1
Answer:
The given program is written in Java.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double a,b;
System.out.print("Enter the length: ");
a=sc.nextDouble();
System.out.print("Enter the breadth: ");
b=sc.nextDouble();
if(a==b)
System.out.println("It is a square.");
else
System.out.println("It is a rectangle.");
sc.close();
}
}
Explanation:
- Logic is very simple, if both length and breadth are same, then it is a square or else it is a rectangle.
- Using this logic, the problem is solved.
See the attachments for output.
•••♪
Attachments:
Similar questions
Political Science,
30 days ago
English,
30 days ago
Computer Science,
2 months ago
Math,
2 months ago
English,
9 months ago
Math,
9 months ago