Quadratic Equation
Write a program that will determine the roots of quadratic equations ax^2 + bx +c. the program should repeatedly prompt the user for values of a, b, and c. For each set of values, the program should solve the corresponding equation, if it has a solution, or print an appropriate message, if it has no solution.
Your console should look similart to:
Do you want to solve an equation (y/n)? y
Enter a: 1
Enter b: -5
Enter c: 6
Root1: 2.0
Root2: 3.0
Do you want to solve an equation (y/n)? y
Enter a: 1
Enter b: -1
Enter c: 4.25
Root1: real part: 0.5 imaginary part: -2.0
Root2: real part: 0.5 imaginary part: 2.0
View Answers
March 5, 2010 at 11:49 AM
Hi Friend,
Try the following code:
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);
}
}
}
Thanks
Related Tutorials/Questions & Answers:
quadratic equationquadratic 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 BeginnersQuadratic 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 equationJava 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
ModuleNotFoundError: No module named 'quadratic'ModuleNotFoundError: No module named '
quadratic' Hi,
My Python... '
quadratic'
How to remove the ModuleNotFoundError: No module named '
quadratic' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'quadratic'ModuleNotFoundError: No module named '
quadratic' Hi,
My Python... '
quadratic'
How to remove the ModuleNotFoundError: No module named '
quadratic' error?
Thanks
Hi,
In your python environment you
extract equationextract equation I want to extract
equation from doc.
Hi Friend,
Which
equation you want to extract from the word document?
Clarify this!
Thanks
Extarct equationExtarct 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
ModuleNotFoundError: No module named 'Equation'ModuleNotFoundError: No module named '
Equation' Hi,
My Python... '
Equation'
How to remove the ModuleNotFoundError: No module named '
Equation... to install padas library.
You can install
Equation python with following
ModuleNotFoundError: No module named 'Equation'ModuleNotFoundError: No module named '
Equation' Hi,
My Python... '
Equation'
How to remove the ModuleNotFoundError: No module named '
Equation... to install padas library.
You can install
Equation python with following
Extracting equation from any documentExtracting
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
javajava how to write a java program to solve
quadratic equation javajava how to write a java program to solve a
quadratic equation 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...; this component.
QuadCurve2D.Double(): This QuadCurve2D
class is defined as a
quadratic parametric curve segment in (x, y) coordinate
and the
quadratic parametric
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 programmeplease 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 programming - Java Beginnersjava 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
java program - JavaMailjava 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
Problem reading word fileProblem 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
Round of to a multiple of 5 without using functionRound 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 functionRound 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
about array in javaabout 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
javajava 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
Java ProgramJava 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