answersLogoWhite

0

import java.io.*;

public class quadratic

{

private String str;

public quadratic()

{

str = "";

}

public quadratic(String str)

{

this.str = str;

}

public void accept()throws IOException

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the equation in terms of x \nEg: 1x^2+4x+5=0 \nAnd you will receive the possible results of x");

str= br.readLine();

}

public void solve()

{

String A[]=new String [8];

int l=str.length();

int j=0;

char c=' ';

String w="";

for(int i=0;i<7;i++)

{

while(true)

{

c=str.charAt(j);

if(c!='+'&&c!='-'&&c!='=')

w=w+c;

else

{

if(i==4)

A[i]="0"+w;

else

A[i]=w;

i++;

if(i>6)

break;

A[i]=" "+c;

j++;

break;

}

j++;

if(j>=l)

break;

}

w="";

}

System.out.println(A[0]);

System.out.println(A[2]);

System.out.println(A[6]);

int len=A[0].length();

String M=A[0].substring(0,(len-3));

len=A[2].length();

String B=A[2].substring(0,len-1);

int a=Integer.parseInt(M);

int b=Integer.parseInt(B);

int C=Integer.parseInt(A[4]);

if(A[3].equals(" -"))

C=-C;

if(A[1].equals(" -"))

b=-b;

double D=(double)Math.sqrt(b*b-4*a*C);

double ans1=(-b+D)/(2*a);

double ans2=(-b-D)/(2*a);

System.out.println("The values of x are: "+ans1+" and "+ans2);

}

public static void main(String args[])throws IOException

{

quadratic ob = new quadratic();

ob.accept();

ob.solve();

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Write a program to find the square root of the quadratic equation using flow chart?

You don't need a flow chart for that; just use the quadratic formula directly; most programming languages have a square root function or method. You would only need to do this in many small steps if you use Assembly programming. The formulae would be something like this: x1 = (-b + sqrt(b^2 - 4*a*c)) / (2 * a) and x2 = (-b - sqrt(b^2 - 4*a*c)) / (2 * a) where a, b, and c are the coefficients of the quadratic equation in standard form, and x1 and x2 are the solutions you want.


How do you write Square program using vb?

write a vb program to find the magic square


Write a Qbasic program to find the root of a quadratic equation using the formula if the result is less than 0 the program should print the root are immerginary and end the program?

(Uses Square Root Function) PRINT "Ax^2 + Bx + C = 0" INPUT "A = ", A INPUT "B = ", B INPUT "C = ", C D = B * B - 4 * A * C IF D &gt; 0 THEN DS = SQR(D) PRINT "REAL ROOTS:", (-B - D) / (2 * A), (-B + D) / (2 * A) ELSE IF D = 0 THEN PRINT "DUPLICATE ROOT:", (-B) / (2 * A) ELSE DS = SQR(-D) PRINT "COMPLEX CONJUGATE ROOTS:", (-B / (2 * A)); "+/-"; DS / (2 * A); "i" END IF END IF


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


Write a program in qbasic to make a hut using print statemant?

a triangle then a square :)

Related Questions

Write an algorithm to find the root of quadratic equation?

Write an algorithm to find the root of quadratic equation


Algorithm to find the roots of a quadratic equation?

The easiest way to write a generic algorithm is to simply use the quadratic formula. If it is a computer program, ask the user for the coefficients a, b, and c of the generic equation ax2 + bx + c = 0, then just replace them in the quadratic formula.


How do you write a poem on the roots of the quadratic equation?

2000X=Y2KoverZzz?


How did you write each quadratic equation in standard form?

readuse the answer


Can you write an equation that includes the keyword "quadratic"?

An example of a quadratic equation is ( ax2 bx c 0 ), where ( a ), ( b ), and ( c ) are constants and ( x ) is the variable.


Write a program in C programming language that computes the roots of the quadratic equation ax2 plus bx plus c?

Write your program and if you are having a problem post it here with a description of the problem you are having. What you are asking is for someone to do your homework for you.


How do you write a pseudo code for find the quadratic equation?

computer scince


How do you write a quadratic equation in standard form?

ax2 + bx + c


How would you go about solving a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 then the roots (solutions) of the equation are: [-b &plusmn; &radic;(b2 - 4*a*c)]/(2*a)


When the roots are equal of a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 The roots are equal if and only if b2 - 4ac = 0. The expression, b2-4ac is called the [quadratic] discriminant.


Write an algorithm and draw a flowchart that will calculate the roots of quadratic equation?

dejene


Write a program to find the square root of the quadratic equation using flow chart?

You don't need a flow chart for that; just use the quadratic formula directly; most programming languages have a square root function or method. You would only need to do this in many small steps if you use Assembly programming. The formulae would be something like this: x1 = (-b + sqrt(b^2 - 4*a*c)) / (2 * a) and x2 = (-b - sqrt(b^2 - 4*a*c)) / (2 * a) where a, b, and c are the coefficients of the quadratic equation in standard form, and x1 and x2 are the solutions you want.