EXPERIMENT:1.
StudentName: UID:
Branch: Section/Group:
Semester: Date ofPerformance:
Subject Name: Subject Code:
1. Aim/Overview of thepractical: Write a program to find roots of quadratic equation
2. Task to bedone:Write a program to find roots of quadratic equation
3. Algorithm/Flowchart:
Create a scanner class object
Take 3 double value input
fromuser
Calculate Discriminant with the
formula(sqrt(b*b-4*a*c))
Check:-
if discriminant greater than zero roots will be real anddifferent
if discriminant equals zero roots will be same andreal
if discriminant less than zero roots will be complex and different
Print the result
4. Steps forexperiment/practical:
Take Input from User
Remember a cannot
bezero
Find roots with the help
ofAboveAlgorithm
Print the Result
3. CODE:
import [Link];
public class one{
public static void main(String[] args)
{ Scanner sc = new Scanner([Link]);
[Link]("Enter Value of a:");
double a = [Link]();
if(a==0){
[Link]("a Cannot be Zero");
}
else{
[Link]("Enter Value of b:");
double b = [Link]();
[Link]("Enter Value of c:");
double c = [Link]();
double determinant = (b*b)-(4*a*c);
double sqroot = [Link](determinant);
double r1,r2;
if(determinant>0){
[Link]("\nRoot's Are Real and Different:");
r1 = (-b + sqroot)/(2*a);
r2 = (-b - sqroot)/(2*a);
[Link]("Root1 = %.2f \nRoot2 = %.2f", r1, r2);
else if(determinant==0){
[Link]("\nRoot's Are Real and Equal:");
r1=r2 = -b/(2*a);
[Link]("Root1 = %.2f \nRoot2 = %.2f",r1,r2);
else{
[Link]("\nRoot's Are Complex and Different:");
double real = -b/(2*a);
double imaginary = [Link](-determinant)/(2*a);
[Link]("Root-1 = %.2f + %.2fi\n",real,imaginary);
[Link]("Root-2 = %.2f - %.2fi\n",real,imaginary);
4. Image of sample output to be attachedhere
BEFARTME9T0F N A A C A
GR A D E¥
Discover. Learn. Empower.
«
*W I•
ACCREDITED UNIVERSITY
Learning outcomes (What I have learnt):
1. Use of ScannerClass
2. Java Syntax
3. Use of ConditionalStatement
4. Java Input and OutputFunctions
5. Arithmetic operation and MathClass
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.
BEFARTME9T0F N A A C A
GR A D E¥
cu ) Discover. Learn. Empower.
«
*W I•
ACCREDITED UNIVERSITY