i cNT GET ANSWER FOR THIS QUESTION

Ads
 

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
i need to answer this Question but i can't do it probably
i need to answer this Question but i can't do it probably   use the web to locate the lyrics to the traditional song"The Twelve Days of Christmas" the song contains a list of gifts received for the holiday.the list is cumulative
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
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
how to get following answer in turbo c program
how to get following answer in turbo c program  input 123456789 output 1 2 3 4 5 6 7 8 9
please i want someone to answer me pleeeeeeeeeeeeease...
please i want someone to answer me pleeeeeeeeeeeeease...    Write a JAVA program using 2D array to auto-grade exams. For a class of N students, your... answer key as Final Array in your program.( using 2D array
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
ModuleNotFoundError: No module named 'okiti-cnt-to-cnt'
ModuleNotFoundError: No module named 'okiti-cnt-to-cnt'  Hi, My... named 'okiti-cnt-to-cnt' How to remove the ModuleNotFoundError: No module named 'okiti-cnt-to-cnt' error? Thanks   Hi, In your
hi,i'am new to Jsp.Can some one please let me know an answer for this question?
hi,i'am new to Jsp.Can some one please let me know an answer for this question?  how do we upload an xml file and validate them against WIPO DTD
how i can get jqfade.js library
how i can get jqfade.js library  how i can get jqfade.j script library
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz  /* * To change this template, choose Tools | Templates * and open the template in the editor
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz  /* * To change this template, choose Tools | Templates * and open the template in the editor
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 have posted a number of question but no one has answered?
I have posted a number of question but no one has answered?  No one has responded for ten days now. However my first question was answered on the same day. Is there a limit to the number of questions you can ask or am I doing
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
there are class A & class B.How can i get members of class A& B?
there are class A & class B.How can i get members of class A& B?  there are class A & class B.How can i get members of class A& B
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

Ads