i cNT GET ANSWER FOR THIS QUESTION
The roots of the quadratic equation ax2+bx+c=0, aïâ??¹0 are given by the following formula:
x=(-bÃ?±âË?Å¡(b^2-4ac))/2a
In this formula. The term b2-4ac is called the discriminant . If b2-4ac=0, Then the equation has a single(repeated) root. If b2-4ac<0, the equation has two complex roots. Write a program that prompts the user to input the value of a(the coefficient of x2), b(the coefficient of x), and c (the constant term, and output the types of roots of the equation. Furthermore, if b2- 4ac � 0, the program should output the roots of the quadratic equation. (Hint: Use the method pow or sqrt from the class Math to calculate the square root.
View Answers
September 19, 2012 at 4:56 PM
Here is a java example that finds the roots of the quadratic equation.
import java.util.*;
class QuadraticEquation
{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Do you want to solve an equation (y/n): ");
String st=input.next();
if(st.equals("y")){
System.out.print("Enter the value of a: ");
double a=input.nextDouble();
System.out.print("Enter the value of b: ");
double b=input.nextDouble();
System.out.print("Enter the value of c: ");
double c=input.nextDouble();
double eq=b*b-4*a*c;
double r1= -b+Math.sqrt(eq);
double r2= -b-Math.sqrt(eq);
double Root1=r1/2*a;
double Root2=r2/2*a;
System.out.println("Root 1 ="+Root1);
System.out.println("Root 2 ="+Root2);
}
else{
System.exit(0);
}
}
}
Ads
Related Tutorials/Questions & Answers:
i cNT GET ANSWER FOR THIS QUESTION
i cNT GET ANSWER FOR THIS QUESTION The roots of the quadratic equation ax2+bx+c=0, aïâ??¹0 are given by the following formula:
x=(-bÃ?±âË?Å¡(b^2-4ac))/2a
In this formula. The term b2-4ac is called
Advertisements
pls answer these question
pls
answer these question Write a program that prompts the user to input the length and width of a rectangle.
Then calculate and prints the rectangleâ??s area and perimeter.
import java.io.*;
class rectangle
help i want it now the answer pleas...
help
i want it now the
answer pleas... write a program that will display the exactly output as below:
Hints: declare and initialize value of array in double type.Read and write all elements of array.perform the multiply
how do i solve this question?
how do
i solve this
question? 1.Define a class named Circle with the following properties:
a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
How do I get started with Bootstrap
How do
I get started with Bootstrap Hi,
I am new to Bootstrap and want to learn it in. What all things
I should know before starting Bootstrap?
How do
I get started with Bootstrap?
Thanks
How do I get started with Bootstrap
How do
I get started with Bootstrap Hi,
I am new to Bootstrap and want to learn it in. What all things
I should know before starting Bootstrap?
How do
I get started with Bootstrap?
Thanks
Question Answer
website.
If you found the
question you can read the
answer if it solves your...?
Browse Latest Questions
Question-
Answer Guidelines...
Here, you can post your desired
question. For
posting any
question / query
PureStack question---i dont know how to do this
PureStack
question---
i dont know how to do this Write a stack class ArrayStack.java implements PureStack interface that reads in strings from... the queue
g. H and
I join the queue
h. G leaves the queue
i. H and
I leave
PureStack question---i dont know how to do this
PureStack
question---
i dont know how to do this Write a stack class ArrayStack.java implements PureStack interface that reads in strings from... the queue
g. H and
I join the queue
h. G leaves the queue
i. H and
I leave
ModuleNotFoundError: No module named 'cnt'
ModuleNotFoundError: No module named '
cnt' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
cnt'
How to remove the ModuleNotFoundError: No module named '
cnt' error
how i want to create a coding by this question?
how
i want to create a coding by this
question? Design and write a class named Person and its two subclasses named Student and Employee.
Make Lecturer and Admin subclasses of Employee.
A person has a name, address, phone number
How can I get into big data?
How can
I get into big data? Hi,
I am beginner in Data Science...
get into big data?
Try to provide me good examples or tutorials links so that
I can learn the
topic "How can
I get into big data?". Also tell me
How do I get a job in AI field?
How do
I get a job in AI field? Hi,
I am beginner in Data Science...
I get a job in AI field?
Try to provide me good examples or tutorials links so that
I can learn the
topic "How do
I get a job in AI field?". Also
Can I get a job with just python?
Can
I get a job with just python? Hi,
I am beginner in Data Science and machine learning field.
I am searching for
the tutorials to learn:
Can
I... so that
I can learn the
topic "Can
I get a job with just python?"
How do I get a job in AI?
How do
I get a job in AI? Hi,
I am beginner in Data Science and machine learning field.
I am searching for
the tutorials to learn:
How do
I get... learn the
topic "How do
I get a job in AI?". Also tell me which
Can I learn Python at 45 and get a job?
Can
I learn Python at 45 and
get a job? Hi,
I am beginner in Data Science and machine learning field.
I am searching for
the tutorials to learn:
Can
I learn Python at 45 and
get a job?
Try to provide me good examples
How can I get IBM certification for free?
How can
I get IBM certification for free? Hi,
I am beginner in Data...:
How can
I get IBM certification for free?
Try to provide me good examples or tutorials links so that
I can learn the
topic "How can
I get IBM
I am getting error.How can i get details
I am getting error.How can
i get details Exception in thread "main" java.sql.SQLException: Listener refused the connecti
n with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect
I cant get values in MS acces in tables
I cant
get values in MS acces in tables
I got problem in sending values from servlet .
*
i am using ms acces
*
i cant display my values but der... sta = con.createStatement();
int
i=sta.executeUpdate("insert
If Sessin Contain Array how can i get each value.
If Sessin Contain Array how can
i get each value. sir,
i m trying to
get value form session and session contain array
i mean ..
whatever... to use this value in different conditions..so how can
i get it..
Thank u