Page 107 - CA_Blue( J )_Class10
P. 107

5          {
                   6              Scanner sc= new Scanner (System.in);

                   7              double u,t,a,s;
                   8              System.out.print("Enter initial velocity in meter/second: ");

                   9              u=sc.nextDouble();

                  10               System.out.print("Enter the acceleration of the body in meter/second
                                     +sq.: ");
                  11              a=sc.nextDouble();

                  12              System.out.print("Enter the time travelled in seconds: ");
                  13              t=sc.nextDouble();

                  14              s=(u*t) +1.0/2.0*a*Math.pow(t,2);
                  15              System.out.println("The distance travelled: "+s+" meters ");

                  16          }
                  17      }

                 You will get the following output:












                               To input three real numbers as arguments of main( ) method and calculate the roots of the quadratic
                  Program 3
                               equation using the following formula:
                                            2
                                     -b ±    b  - 4ac
                                x =
                                          2a
                                       2
                               Where, b  - 4ac is known as the determinant of a quadratic equation.
                   1 class quadratic_equation
                   2     {

                   3         public static void main (double a, double b, double c)
                   4         {
                   5             double d,r1,r2;

                   6             d = Math.pow(b,2) - (4*a*c);
                   7             if(d>0)
                   8             {

                   9                 r1 = (-b + Math.sqrt(d)) / (2.0 * a);
                  10                 r2 = (-b - Math.sqrt(d)) / (2.0 * a);

                  11                 System.out.println("The roots are " + r1 + " and " + r2);
                  12             }



                                                                                                                       105
                                                                                          Mathematical Library Methods   105
   102   103   104   105   106   107   108   109   110   111   112