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
Math,
1 month ago
Computer Science,
3 months ago
Math,
3 months ago
English,
10 months ago
Math,
10 months ago