i>Write a program to find the area of a circle,rectangle and a square ii>Write a program to find the diagonal of a rectangle iii>The distance between two points A and B of a straight line cwhose coordinates are and are calculated as AB=root over(y2-y1)+(x2-x1) Write a program in java to calculate the distance between the two points by taking the coordinates as input
Answers
HELLO!
Here's the Java code for your problems:
(i)
// Area of circle, rectangle and square
class Area
{
public static void main(r, l, b, a)
{
double cir = 3.14 * r * r;
double rect = l * b;
double sq = a * a;
System.out.println("Area of circle: " + cir + "\nArea of rectangle: " + rect + "\n Area of square: " + sq);
}
}
(ii)
// Diagonal of rectangle
class Diagonal
{
public static void main(l, b)
{
double diag = Math.sqrt((l*l) + (b*b));
System.out.println("The diagonal of the rectangle is: " + diag);
}
}
(iii)
// Distance between two points
import java.util.Scanner;
class Distance
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the coordinates of the two points: ");
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
double dist = Math.sqrt((Math.pow((y2-y1), 2)) + (Math.pow((x2-x1), 2)));
System.out.println("The distance is: " + dist);
}
}
Thanks!