- At the top of code, write " import java.lang.Math.*;" this will import a math class and will be helpful to find mathematical problems.
- And then class and main as we already know and now write starting curly braces of main method.
- Declare three variables a,b and c of int type.
- Take three values of a,b and c by using easyin method as these values are required for quadratic equation.
- Write a caller which pass three values a,b and c and choose an appropriate name of if like quadii(a,b,c);
- Now, write the closing curly braces of main method.
- Write method which take three values of a,b and c like public static void quadii(int x, int y, int z). Here x y and z are different from a b and c these can be same also but here values of a,b and c have been transferred into x y and z.
- Write starting curly braces of method quadii.
- declare some variables lets say d e f g
- And four double type o u v
- d=y*y;
- e=4*x*z;
- f=d-e;
- g=2*x;
- o=(double)Math.sqrt(f); ( this will find the square root of f and double will convert the value of f into double )
- u=(-y+o)/g;
- v=(-y-o)/g;
- Now u and v are the two value of quadratic equation and now write output statement.
- System.out.println("Solution set = { "+u+" , "+v+"}");
- Now write the closing curly braces of method quadii.
This blog is made for my dear class fellows to provide algorithms of different problem statements of JAVA.
Tuesday, 31 January 2012
Qudratic equation using method
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment