Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This program solves the quadratic equations(ax^2+bx+c)
- and finds th values of x when user provides th value of a,b and c*/
- import java.io.*;
- class Quadratic
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- double A,B,C,R1,R2,D;
- public void calcRoots() throws IOException
- {
- System.out.println("Enter value of A");
- A=Double.parseDouble(br.readLine());
- System.out.println("Enter value of B");
- B=Double.parseDouble(br.readLine());
- System.out.println("Enter value of C");
- C=Double.parseDouble(br.readLine());
- D=(B*B)-(4*A*C);
- if(D>=0)
- {
- R1=(-B+Math.sqrt(D))/(2*A);
- R2=(-B-Math.sqrt(D))/(2*A);
- System.out.println("Roots are = "+R1+" "+R2);
- }
- else
- System.out.println("Roots are imaginary");
- }
- public static void main(String args[])
- {
- Quadratic q=new Quadratic();
- q.calcRoots();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment