Write a program to find the perimeter of square and rectangle. Formula : ps=4xside (perimeter of square) pr=2(l+b) (perimeter of rectangle) in Java
please give me genuine answers
Answers
Answered by
2
Here we will use Scanner class to write the program where the input will be given by user.
Program Códe :
import java.util.*;
class perimeter
{
public static void main(String args[])
{
double square, rectangle;
Scanner sc = new Scanner(System.in);
System.out.println("Enter side of square:");
int side = sc.nextInt();
System.out.println("Enter length of rectangle:");
System.out.println("Enter breadth of rectangle:");
int length = sc.nextInt();
int breadth = sc.nextInt();
square = 4 * side;
rectangle = 2*(length + breadth);
System.out.println("Perimeter of square="+square);
System.out.println("Perimeter of rectangle="+rectangle);
}
}
For output refer to the attachment.
Attachments:
Similar questions