- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to find the vertex, focus and directrix of a parabola
Following is the Java program to find the vertex, focus and directrix of a parabola −
Example
public class Demo{ public static void find_values(float val_1, float val_2, float val_3){ System.out.println("The value of vertex is (" + (-val_2 / (2 * val_1)) + ", "+ (((4 * val_1 * val_3) - (val_2 * val_2)) / (4 * val_1)) + ")"); System.out.println("The value of focus is (" + (-val_2 / (2 * val_1)) + ", " + (((4 * val_1 * val_3) - (val_2 * val_2) + 1) / (4 * val_1)) + ")"); System.out.println("The value of directrix is " + (int)(val_3 - ((val_2 * val_2) + 1) * 4 * val_1)); } public static void main(String[] args){ float val_1 = 6, val_2 = 2, val_3 = 9; find_values(val_1, val_2, val_3); } }
Output
The value of vertex is (-0.16666667, 8.833333) The value of focus is (-0.16666667, 8.875) The value of directrix is -111
A class named Demo contains a static function that takes in three float values. The formula for vertex, focus and directrix of parabola are substituted with values passed as parameter to the function. In the main unction, the values are defined, and the function is called on these values. The relevant data is displayed on the screen.
Advertisements