Thursday, January 28, 2016

JAVA ELLIPSE AREA: Solve for the Area of Ellipse


Ellipse is an oval shape quite similar with that of a circle but is elongated. I already posted articles related to solving for the area of a squarecirclerectangletriangle and etc. The formula of the area of a circle is somewhat similar with that of the ellipse.



Visit PHP Solve for the Area of Ellipse here.

The program allows a user to input the desired value for a and b, x-axis and y-axis in java language.




Formula














A = Area of an Ellipse


a = distance from the center up to the edge (y-axis)


b = distance from the center to the right or left edge of an ellipse (x-axis)









Java Code
import java.util.Scanner; 
public class Ellipse{

public static void main(String[] args) {

// solve for the area of an ellipse

Scanner console=new Scanner(System.in);
System.out.println("Enter distance in y axis: ");
double a = console.nextDouble();
System.out.println("Enter distance in x axis: ");
double b = console.nextDouble();
double area=Math.PI*a*b;
System.out.printf("The area of an ellipse is %.2f",area);
}
}
Output













The above output formats the result in two (2) decimal places using the printf function and using the format specifier which is %.2f.

JAVA ELLIPSE AREA: Solve for the Area of Ellipse

JAVA ELLIPSE AREA: Solve for the Area of Ellipse Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment