Share on Google+Share on Google+

Supriya Kurian
quadratic equation
1 Answer(s)      6 years and 4 months ago
Posted in : Java Beginners

program to find roots of a quadratic equation?

Ads

View Answers

December 23, 2010 at 12:05 PM


Hi Friend,

Try the following code:

import java.util.*;
class FindRootsOfQuadraticEquation{
public static void main(String args[]) throws Exception{
double root,root1,root2;
Scanner input=new Scanner(System.in);
System.out.println("Quadratic Equation is ax2+bx+c");
System.out.println("Enter value of a");
int a=input.nextInt();
System.out.println("Enter value of b");
int b=input.nextInt();
System.out.println("Enter value of c");
int c=input.nextInt();
int d=(b*b)-(4*a*c);
if(d>0)
{
root1=(-b + Math.sqrt(d))/(2*a);
root2=(-b - Math.sqrt(d))/(2*a);
System.out.println("Roots are distinct");
System.out.println( root1 + "," + root2);
}
else if(d==0)
{
root=(-b)/(2*a);
System.out.println("Only one root is distinct");
System.out.println(root);
}
else if(d<0)
{
System.out.println("Roots are imaginary");
}
}
}

Thanks










Related Tutorials/Questions & Answers:
quadratic equation
quadratic equation  program to find roots of a quadratic equation?   Hi Friend, Try the following code: import java.util.*; class...); System.out.println("Quadratic Equation is ax2+bx+c"); System.out.println("Enter value
Quadratic Equation - Java Beginners
Quadratic Equation  Write a program that will determine the roots of quadratic equations ax^2 + bx +c. the program should repeatedly prompt the user... the corresponding equation, if it has a solution, or print an appropriate message
Advertisements
Java find the roots of quadratic equation
Java find the roots of quadratic equation In this tutorial, you will learn how to find the roots of quadratic equation. Quadratic Equations are always in the form ax2 + bx + c = 0. Every Quadratic equation has two roots
extract equation
extract equation  I want to extract equation from doc.   Hi Friend, Which equation you want to extract from the word document? Clarify this! Thanks
Extarct equation
Extarct equation  Want to extarct equation of the form ax+by+c=0 from any word document.   Hi Friend, Try this: import java.io.*; import java.util.*; import org.apache.poi.hwpf.HWPFDocument; import
Extracting equation from any document
Extracting equation from any document  how can i extract equation from any word document?   Hello Friend, If you want to extract data from the word file, then visit the following link: Extract data from word document
how to find the roots of polynomial equation of 'n'th degree in java
how to find the roots of polynomial equation of 'n'th degree in java  i am new to java field and i wanted to find the roots of nth degree polynomial equation pls help me. thanks
write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n
write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n  write a program to evaluate the following investment equation make use of wrapper class v=p(1+r)rest to n
java
java  how to write a java program to solve quadratic equation
java
java  how to write a java program to solve a quadratic equation
Biquadratic regression analysis - Java Beginners
Biquadratic regression analysis  Hi Is there any code available to solve bi quadratic equation using regression analysis? Thanks in advance
Draw different curves with QuadCurve2D
Draw different curves with QuadCurve2D       This section illustrates you how to draw different curves with the class QuadCurve2D. The QuadCurve2D class provides a quadratic
How to Create CurveDraw In Java
, enables you to create a quadratic or cubic segment. Here, you will see...; QuadCurve2D.Double(): This QuadCurve2D class is defined as a quadratic parametric curve segment in (x, y) coordinate and the quadratic parametric curve segment
i cNT GET ANSWER FOR THIS QUESTION
- 4ac â?¥ 0, the program should output the roots of the quadratic equation...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
please help.. this my importtant project..!!!!!
: Solving quadratic equations. The two roots of a quadratic equation ax2 + bx... is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root
please solve the programme
please solve the programme  Develop a java program to find the roots of a quadratic equation ax2+bx+c=0, with the following specification... & d is the discriminant, x & x2 are the roots of the equation
java program - JavaMail
java program  if int a = 48 find a = a+++++a answer shows 48+49+1 97+1 98 pls clarify find a equation, as I think there some operator mistake tapas
java programming - Java Beginners
java programming  asking for the java code for solving mathematical equation with two unknown .thnx ahead..  Hi Friend, Please clarify your question. Which mathematical equations you want to solve? Thanks
setting RGB for a circle
not able to find its appropriate equation help please
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Round of to a multiple of 5 without using function
Round of to a multiple of 5 without using function  Please help me out... U enter values like 239, 2543.876, 962.... Give me an equation without using any function which will give output of 240, 2545, 960 respectively
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
about array in java
about array in java  speed of a vehicle is measured using the total time and the distance by using the equation given bellow speed(km/hour)=distance(km)/time(hour) Each vehicle is given a unique identification number
java programming problem - Java Beginners
those solution sets.   go through the linear Equation book we must
Java Program
Java Program  Problem Statement You are required to write a program which, when given a sequence of integers, creates an equation. All but the last... an expression. Like in any good equation, the LHS must equal the RHS. The operators
java
java  1.Design then implement a Java program that defines and initializes the coefficients of a linear equation 2x + 4.5 = 0. Also, make your program compute and display the solution of the equation 2.Design then implement
Project about hashing and Avl TREES
be quadratic and when click on read data button must read from file in this manner # space
project on avl tree and hashing
rehashing ,the hash tabel function is x% hash tabel size and must be quadratic
project about AVL tree and hashing
be quadratic and when click on read data button must read from file in this manner
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads